1 From patchwork Tue Mar 12 09:51:42 2019
2 Content-Type: text/plain; charset="utf-8"
4 Content-Transfer-Encoding: 7bit
5 X-Patchwork-Submitter: Stanislaw Gruszka <sgruszka@redhat.com>
6 X-Patchwork-Id: 10848961
7 X-Patchwork-Delegate: kvalo@adurom.com
8 From: Stanislaw Gruszka <sgruszka@redhat.com>
9 To: linux-wireless@vger.kernel.org
10 Cc: =?utf-8?q?Tomislav_Po=C5=BEega?= <pozega.tomislav@gmail.com>,
11 Daniel Golle <daniel@makrotopia.org>, Felix Fietkau <nbd@nbd.name>,
12 Mathias Kresin <dev@kresin.me>
13 Subject: [PATCH v3 3/4] rt2x00: check number of EPROTO errors
14 Date: Tue, 12 Mar 2019 10:51:42 +0100
15 Message-Id: <1552384303-29529-4-git-send-email-sgruszka@redhat.com>
16 In-Reply-To: <1552384303-29529-1-git-send-email-sgruszka@redhat.com>
17 References: <1552384303-29529-1-git-send-email-sgruszka@redhat.com>
19 Some USB host devices/drivers on some conditions can always return
20 EPROTO error on submitted URBs. That can cause infinity loop in the
23 Since we can have single EPROTO errors we can not mark as device as
24 removed to avoid infinity loop. However we can count consecutive
25 EPROTO errors and mark device as removed if get lot of it.
26 I choose number 10 as threshold.
28 Reported-and-tested-by: Randy Oostdyk <linux-kernel@oostdyk.com>
29 Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
31 drivers/net/wireless/ralink/rt2x00/rt2x00.h | 1 +
32 drivers/net/wireless/ralink/rt2x00/rt2x00usb.c | 22 +++++++++++++++++++---
33 2 files changed, 20 insertions(+), 3 deletions(-)
35 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00.h
36 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
37 @@ -1017,6 +1017,7 @@ struct rt2x00_dev {
38 unsigned int extra_tx_headroom;
40 struct usb_anchor *anchor;
41 + unsigned int num_proto_errs;
43 /* Clock for System On Chip devices. */
45 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
46 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
49 #include "rt2x00usb.h"
51 +static bool rt2x00usb_check_usb_error(struct rt2x00_dev *rt2x00dev, int status)
53 + if (status == -ENODEV || status == -ENOENT)
56 + if (status == -EPROTO || status == -ETIMEDOUT)
57 + rt2x00dev->num_proto_errs++;
59 + rt2x00dev->num_proto_errs = 0;
61 + if (rt2x00dev->num_proto_errs > 3)
68 * Interfacing with the HW.
70 @@ -57,7 +73,7 @@ int rt2x00usb_vendor_request(struct rt2x
74 - if (status == -ENODEV || status == -ENOENT) {
75 + if (rt2x00usb_check_usb_error(rt2x00dev, status)) {
76 /* Device has disappeared. */
77 clear_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
79 @@ -321,7 +337,7 @@ static bool rt2x00usb_kick_tx_entry(stru
81 status = usb_submit_urb(entry_priv->urb, GFP_ATOMIC);
83 - if (status == -ENODEV || status == -ENOENT)
84 + if (rt2x00usb_check_usb_error(rt2x00dev, status))
85 clear_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
86 set_bit(ENTRY_DATA_IO_FAILED, &entry->flags);
87 rt2x00lib_dmadone(entry);
88 @@ -410,7 +426,7 @@ static bool rt2x00usb_kick_rx_entry(stru
90 status = usb_submit_urb(entry_priv->urb, GFP_ATOMIC);
92 - if (status == -ENODEV || status == -ENOENT)
93 + if (rt2x00usb_check_usb_error(rt2x00dev, status))
94 clear_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
95 set_bit(ENTRY_DATA_IO_FAILED, &entry->flags);
96 rt2x00lib_dmadone(entry);