All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stanislaw Gruszka <sgruszka@redhat.com>
To: linux-wireless@vger.kernel.org
Cc: "Randy Oostdyk" <linux-kernel@oostdyk.com>,
	"Tomislav Požega" <pozega.tomislav@gmail.com>,
	"Daniel Golle" <daniel@makrotopia.org>,
	"Felix Fietkau" <nbd@nbd.name>, "Mathias Kresin" <dev@kresin.me>
Subject: [PATCH v2 2/3] rt2x00: check number of EPROTO errors
Date: Thu, 20 Dec 2018 16:16:10 +0100	[thread overview]
Message-ID: <1545318971-28351-2-git-send-email-sgruszka@redhat.com> (raw)
In-Reply-To: <1545318971-28351-1-git-send-email-sgruszka@redhat.com>

Some USB host devices/drivers on some conditions can always return
EPROTO error on submitted URBs. That can cause infinity loop in the
rt2x00 driver.

Since we can have single EPROTO errors we can not mark as device as
removed to avoid infinity loop. However we can count consecutive
EPROTO errors and mark device as removed if get lot of it.
I choose number 10 as threshold.

Reported-and-tested-by: Randy Oostdyk <linux-kernel@oostdyk.com>
Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
---
 drivers/net/wireless/ralink/rt2x00/rt2x00.h    |  1 +
 drivers/net/wireless/ralink/rt2x00/rt2x00usb.c | 22 +++++++++++++++++++---
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00.h b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
index 94459d5ee01b..88e0dc803227 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2x00.h
+++ b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
@@ -1022,6 +1022,7 @@ struct rt2x00_dev {
 	unsigned int extra_tx_headroom;
 
 	struct usb_anchor *anchor;
+	unsigned int num_proto_errs;
 
 	/* Clock for System On Chip devices. */
 	struct clk *clk;
diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
index 086aad22743d..60b8bccab83d 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
+++ b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
@@ -31,6 +31,22 @@
 #include "rt2x00.h"
 #include "rt2x00usb.h"
 
+static bool rt2x00usb_check_usb_error(struct rt2x00_dev *rt2x00dev, int status)
+{
+	if (status == -ENODEV || status == -ENOENT)
+		return true;
+	
+	if (status == -EPROTO)
+		rt2x00dev->num_proto_errs++;
+	else
+		rt2x00dev->num_proto_errs = 0;
+
+	if (rt2x00dev->num_proto_errs > 10)
+		return true;
+
+	return false;
+}
+
 /*
  * Interfacing with the HW.
  */
@@ -57,7 +73,7 @@ int rt2x00usb_vendor_request(struct rt2x00_dev *rt2x00dev,
 		if (status >= 0)
 			return 0;
 
-		if (status == -ENODEV || status == -ENOENT) {
+		if (rt2x00usb_check_usb_error(rt2x00dev, status)) {
 			/* Device has disappeared. */
 			clear_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
 			break;
@@ -321,7 +337,7 @@ static bool rt2x00usb_kick_tx_entry(struct queue_entry *entry, void *data)
 
 	status = usb_submit_urb(entry_priv->urb, GFP_ATOMIC);
 	if (status) {
-		if (status == -ENODEV || status == -ENOENT)
+		if (rt2x00usb_check_usb_error(rt2x00dev, status))
 			clear_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
 		set_bit(ENTRY_DATA_IO_FAILED, &entry->flags);
 		rt2x00lib_dmadone(entry);
@@ -410,7 +426,7 @@ static bool rt2x00usb_kick_rx_entry(struct queue_entry *entry, void *data)
 
 	status = usb_submit_urb(entry_priv->urb, GFP_ATOMIC);
 	if (status) {
-		if (status == -ENODEV || status == -ENOENT)
+		if (rt2x00usb_check_usb_error(rt2x00dev, status))
 			clear_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
 		set_bit(ENTRY_DATA_IO_FAILED, &entry->flags);
 		rt2x00lib_dmadone(entry);
-- 
2.7.5


  reply	other threads:[~2018-12-20 15:16 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-20 15:16 [PATCH v2 1/3] rt2x00: use ratelimited variants dev_warn/dev_err Stanislaw Gruszka
2018-12-20 15:16 ` Stanislaw Gruszka [this message]
2019-01-07 12:47   ` [PATCH v2 2/3] rt2x00: check number of EPROTO errors Jeroen Roovers
2019-01-07 15:09     ` Stanislaw Gruszka
2019-01-08  9:30       ` Jeroen Roovers
2019-01-08 10:09         ` Jeroen Roovers
2019-01-08 11:04         ` Tom Psyborg
2019-01-09  6:17           ` Jeroen Roovers
2019-01-09 11:33             ` Stanislaw Gruszka
2019-01-10  7:49               ` Jeroen Roovers
2019-01-10 14:29                 ` Jeroen Roovers
2019-01-16 11:11                   ` Stanislaw Gruszka
2019-01-22 17:32                   ` Jeroen Roovers
2019-02-12 15:02                     ` Stanislaw Gruszka
2018-12-20 15:16 ` [PATCH v2 3/3] rt2x00: do not print error when queue is full Stanislaw Gruszka
2018-12-20 17:52   ` Tom Psyborg
2018-12-21  9:59     ` Stanislaw Gruszka
2018-12-22 13:12       ` Tom Psyborg
2018-12-25 22:43         ` Tom Psyborg
2018-12-27 10:32           ` Stanislaw Gruszka
2018-12-27 10:25         ` Stanislaw Gruszka
2018-12-28  0:45           ` Tom Psyborg
2019-01-02  8:19             ` Stanislaw Gruszka
2019-02-09 11:03               ` Stanislaw Gruszka
2019-02-09 11:11                 ` Tom Psyborg
2019-02-09 11:56                   ` Stanislaw Gruszka
2019-02-09 12:28                     ` Tom Psyborg
2019-02-09 15:38                       ` Daniel Golle
2019-02-09 16:29                         ` Tom Psyborg
2019-02-09 17:28                           ` Daniel Golle
2019-03-19  2:37                             ` Tom Psyborg
2019-02-10  9:57                       ` Stanislaw Gruszka
2018-12-21 11:19 ` [PATCH v2 1/3] rt2x00: use ratelimited variants dev_warn/dev_err Joe Perches
2018-12-21 11:57   ` Stanislaw Gruszka
2018-12-21 12:48     ` Joe Perches
2018-12-21 12:51       ` Stanislaw Gruszka
2019-01-29 12:30     ` Kalle Valo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1545318971-28351-2-git-send-email-sgruszka@redhat.com \
    --to=sgruszka@redhat.com \
    --cc=daniel@makrotopia.org \
    --cc=dev@kresin.me \
    --cc=linux-kernel@oostdyk.com \
    --cc=linux-wireless@vger.kernel.org \
    --cc=nbd@nbd.name \
    --cc=pozega.tomislav@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.