2
0

022-rt2x00-check-number-of-EPROTO-errors.patch 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. From patchwork Tue Mar 12 09:51:42 2019
  2. Content-Type: text/plain; charset="utf-8"
  3. MIME-Version: 1.0
  4. Content-Transfer-Encoding: 7bit
  5. X-Patchwork-Submitter: Stanislaw Gruszka <[email protected]>
  6. X-Patchwork-Id: 10848961
  7. X-Patchwork-Delegate: [email protected]
  8. From: Stanislaw Gruszka <[email protected]>
  9. To: [email protected]
  10. Cc: =?utf-8?q?Tomislav_Po=C5=BEega?= <[email protected]>,
  11. Daniel Golle <[email protected]>, Felix Fietkau <[email protected]>,
  12. Mathias Kresin <[email protected]>
  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: <[email protected]>
  16. In-Reply-To: <[email protected]>
  17. References: <[email protected]>
  18. Some USB host devices/drivers on some conditions can always return
  19. EPROTO error on submitted URBs. That can cause infinity loop in the
  20. rt2x00 driver.
  21. Since we can have single EPROTO errors we can not mark as device as
  22. removed to avoid infinity loop. However we can count consecutive
  23. EPROTO errors and mark device as removed if get lot of it.
  24. I choose number 10 as threshold.
  25. Reported-and-tested-by: Randy Oostdyk <[email protected]>
  26. Signed-off-by: Stanislaw Gruszka <[email protected]>
  27. ---
  28. drivers/net/wireless/ralink/rt2x00/rt2x00.h | 1 +
  29. drivers/net/wireless/ralink/rt2x00/rt2x00usb.c | 22 +++++++++++++++++++---
  30. 2 files changed, 20 insertions(+), 3 deletions(-)
  31. --- a/drivers/net/wireless/ralink/rt2x00/rt2x00.h
  32. +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
  33. @@ -1017,6 +1017,7 @@ struct rt2x00_dev {
  34. unsigned int extra_tx_headroom;
  35. struct usb_anchor *anchor;
  36. + unsigned int num_proto_errs;
  37. /* Clock for System On Chip devices. */
  38. struct clk *clk;
  39. --- a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
  40. +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
  41. @@ -31,6 +31,22 @@
  42. #include "rt2x00.h"
  43. #include "rt2x00usb.h"
  44. +static bool rt2x00usb_check_usb_error(struct rt2x00_dev *rt2x00dev, int status)
  45. +{
  46. + if (status == -ENODEV || status == -ENOENT)
  47. + return true;
  48. +
  49. + if (status == -EPROTO || status == -ETIMEDOUT)
  50. + rt2x00dev->num_proto_errs++;
  51. + else
  52. + rt2x00dev->num_proto_errs = 0;
  53. +
  54. + if (rt2x00dev->num_proto_errs > 3)
  55. + return true;
  56. +
  57. + return false;
  58. +}
  59. +
  60. /*
  61. * Interfacing with the HW.
  62. */
  63. @@ -57,7 +73,7 @@ int rt2x00usb_vendor_request(struct rt2x
  64. if (status >= 0)
  65. return 0;
  66. - if (status == -ENODEV || status == -ENOENT) {
  67. + if (rt2x00usb_check_usb_error(rt2x00dev, status)) {
  68. /* Device has disappeared. */
  69. clear_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
  70. break;
  71. @@ -321,7 +337,7 @@ static bool rt2x00usb_kick_tx_entry(stru
  72. status = usb_submit_urb(entry_priv->urb, GFP_ATOMIC);
  73. if (status) {
  74. - if (status == -ENODEV || status == -ENOENT)
  75. + if (rt2x00usb_check_usb_error(rt2x00dev, status))
  76. clear_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
  77. set_bit(ENTRY_DATA_IO_FAILED, &entry->flags);
  78. rt2x00lib_dmadone(entry);
  79. @@ -410,7 +426,7 @@ static bool rt2x00usb_kick_rx_entry(stru
  80. status = usb_submit_urb(entry_priv->urb, GFP_ATOMIC);
  81. if (status) {
  82. - if (status == -ENODEV || status == -ENOENT)
  83. + if (rt2x00usb_check_usb_error(rt2x00dev, status))
  84. clear_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
  85. set_bit(ENTRY_DATA_IO_FAILED, &entry->flags);
  86. rt2x00lib_dmadone(entry);