[PATCH v2 2/2] wifi: rt2x00: prevent TX_STA_FIFO URB resubmission on error and teardown

From: bin luo

Date: Wed Dec 02 2026 - 07:05:52 EST


From: Bin Luo (University of Electronic Science and Technology of
China) <luob87709@xxxxxxxxx>

Two TX_STA_FIFO polling issues remain on URB failure or if a TX queue
fails to drain before rt2x00usb_uninitialize():

1. In rt2800usb_tx_sta_fifo_read_completed(), a non-zero urb_status (such
as -ENOENT from usb_kill_anchored_urbs() or a bus error on disconnect)
jumps to stop_reading: and runs the rt2800_txstatus_pending() race
recheck meant for normal completion. When TX status is still pending,
it sets TX_STATUS_READING again and returns true to resubmit the
failed URB; if usb_submit_urb() then fails (e.g. -EPERM while killing
anchored URBs), TX_STATUS_READING stays stuck set.

2. In rt2x00usb_uninitialize(), usb_kill_anchored_urbs() runs before
hrtimer_cancel(&rt2x00dev->txstatus_timer) and cancel_work_sync() on
txdone_work, allowing txstatus_timer to fire after anchored URBs were
killed and submit a fresh async TX_STA_FIFO URB.

Clear TX_STATUS_READING and return false directly when urb_status is
non-zero, guard TX_STA_FIFO timer/URB rearming with
DEVICE_STATE_INITIALIZED, and cancel txstatus_timer before
usb_kill_anchored_urbs() as well as after draining txdone_work.

Fixes: f421111b5e69 ("rt2x00: rt2800usb: rework txstatus code")
Fixes: 6232c17438ed ("rt2x00: avoid introducing a USB dependency in
the rt2x00lib module")
Signed-off-by: Bin Luo (University of Electronic Science and
Technology of China) <luob87709@xxxxxxxxx>
---
Changes in v2:
- Split into a separate patch with its own description per Stanislaw
Gruszka's request.
- Clear TX_STATUS_READING and return false directly when urb_status != 0
in rt2800usb_tx_sta_fifo_read_completed() instead of jumping into the
stop_reading: race-window recheck.

Validation:
- scripts/checkpatch.pl --strict: 0 errors, 0 warnings, 0 checks
- W=1 KASAN+LOCKDEP build of rt2800usb.o and rt2x00usb.o:
0 warnings, 0 errors
- QEMU KVM (v7.4-rc4, KASAN+LOCKDEP) tested both standalone (when Queue 0
fails to flush) and together with patch 1/2 across sysfs unbind and
physical USB disconnect: 0 killed-URB resubmissions, 0 warnings,
0 KASAN, 0 Lockdep.

drivers/net/wireless/ralink/rt2x00/rt2800usb.c | 16 ++++++++++++----
drivers/net/wireless/ralink/rt2x00/rt2x00usb.c | 8 +++++++-
2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800usb.c
b/drivers/net/wireless/ralink/rt2x00/rt2800usb.c
index 15de3db..0327785 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2800usb.c
+++ b/drivers/net/wireless/ralink/rt2x00/rt2800usb.c
@@ -99,8 +99,8 @@ static bool
rt2800usb_tx_sta_fifo_read_completed(struct rt2x00_dev *rt2x00dev,
if (urb_status) {
rt2x00_warn(rt2x00dev, "TX status read failed %d\n",
urb_status);
-
- goto stop_reading;
+ clear_bit(TX_STATUS_READING, &rt2x00dev->flags);
+ return false;
}

valid = rt2x00_get_field32(tx_status, TX_STA_FIFO_VALID);
@@ -118,7 +118,8 @@ static bool
rt2800usb_tx_sta_fifo_read_completed(struct rt2x00_dev *rt2x00dev,
if (rt2800_txstatus_timeout(rt2x00dev))
queue_work(rt2x00dev->workqueue, &rt2x00dev->txdone_work);

- if (rt2800_txstatus_pending(rt2x00dev)) {
+ if (rt2800_txstatus_pending(rt2x00dev) &&
+ test_bit(DEVICE_STATE_INITIALIZED, &rt2x00dev->flags)) {
/* Read register after 1 ms */
hrtimer_start(&rt2x00dev->txstatus_timer,
TXSTATUS_READ_INTERVAL,
@@ -126,7 +127,6 @@ static bool
rt2800usb_tx_sta_fifo_read_completed(struct rt2x00_dev *rt2x00dev,
return false;
}

-stop_reading:
clear_bit(TX_STATUS_READING, &rt2x00dev->flags);
/*
* There is small race window above, between txstatus pending check and
@@ -134,6 +134,7 @@ stop_reading:
* here again if status reading is needed.
*/
if (rt2800_txstatus_pending(rt2x00dev) &&
+ test_bit(DEVICE_STATE_INITIALIZED, &rt2x00dev->flags) &&
!test_and_set_bit(TX_STATUS_READING, &rt2x00dev->flags))
return true;
else
@@ -142,6 +143,8 @@ stop_reading:

static void rt2800usb_async_read_tx_status(struct rt2x00_dev *rt2x00dev)
{
+ if (!test_bit(DEVICE_STATE_INITIALIZED, &rt2x00dev->flags))
+ return;

if (test_and_set_bit(TX_STATUS_READING, &rt2x00dev->flags))
return;
@@ -164,6 +167,11 @@ static enum hrtimer_restart
rt2800usb_tx_sta_fifo_timeout(struct hrtimer *timer)
struct rt2x00_dev *rt2x00dev =
container_of(timer, struct rt2x00_dev, txstatus_timer);

+ if (!test_bit(DEVICE_STATE_INITIALIZED, &rt2x00dev->flags)) {
+ clear_bit(TX_STATUS_READING, &rt2x00dev->flags);
+ return HRTIMER_NORESTART;
+ }
+
rt2x00usb_register_read_async(rt2x00dev, TX_STA_FIFO,
rt2800usb_tx_sta_fifo_read_completed);

diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
index c9fbc37..8d77cd5 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
+++ b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
@@ -745,10 +745,16 @@ void rt2x00usb_uninitialize(struct rt2x00_dev *rt2x00dev)
{
struct data_queue *queue;

- usb_kill_anchored_urbs(rt2x00dev->anchor);
+ /*
+ * Cancel txstatus_timer before killing anchored TX_STA_FIFO URBs so
+ * the timer cannot submit new URBs afterwards, then cancel again
+ * after draining txdone_work in case an earlier callback rearmed it.
+ */
hrtimer_cancel(&rt2x00dev->txstatus_timer);
+ usb_kill_anchored_urbs(rt2x00dev->anchor);
cancel_work_sync(&rt2x00dev->rxdone_work);
cancel_work_sync(&rt2x00dev->txdone_work);
+ hrtimer_cancel(&rt2x00dev->txstatus_timer);

queue_for_each(rt2x00dev, queue)
rt2x00usb_free_entries(queue);
--
2.43.0