All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] wifi: rt2x00: prevent txstatus_timer rearm during USB uninitialize
@ 2026-11-26  6:51 Bin Luo (University of Electronic Science and Technology of China)
  2026-12-01 16:39 ` Stanislaw Gruszka
  2026-12-02  6:06 ` Bin Luo (University of Electronic Science and Technology of China)
  0 siblings, 2 replies; 3+ messages in thread
From: Bin Luo (University of Electronic Science and Technology of China) @ 2026-11-26  6:51 UTC (permalink / raw)
  To: stf_xl, johannes; +Cc: linux-wireless, linux-kernel

rt2x00usb_uninitialize() cancels rt2x00dev->txstatus_timer before
calling cancel_work_sync(&rt2x00dev->txdone_work). Because
rt2800usb_work_txdone() calls rt2800usb_async_read_tx_status() and
rearms txstatus_timer, the timer can remain armed after
rt2x00usb_uninitialize() frees queue entries via
rt2x00usb_free_entries(), allowing rt2800usb_tx_sta_fifo_timeout() to
submit new async register-read URBs and queue txdone_work on torn-down
queues.

Because rt2x00lib_uninitialize() clears DEVICE_STATE_INITIALIZED before
calling rt2x00usb_uninitialize(), guard txstatus_timer rearming and
timer-driven async register reads with DEVICE_STATE_INITIALIZED and
cancel txstatus_timer after cancel_work_sync(&rt2x00dev->txdone_work).

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@gmail.com>
---
Found by code inspection. Compile-tested on x86_64 with W=1 and KASAN (drivers/net/wireless/ralink/rt2x00/rt2800usb.o and rt2x00usb.o); not runtime-tested on Ralink USB hardware.

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

diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800usb.c b/drivers/net/wireless/ralink/rt2x00/rt2800usb.c
index 15de3db..57e04c6 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2800usb.c
+++ b/drivers/net/wireless/ralink/rt2x00/rt2800usb.c
@@ -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,
@@ -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..bfd5a81 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
+++ b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
@@ -746,9 +746,9 @@ void rt2x00usb_uninitialize(struct rt2x00_dev *rt2x00dev)
 	struct data_queue *queue;
 
 	usb_kill_anchored_urbs(rt2x00dev->anchor);
-	hrtimer_cancel(&rt2x00dev->txstatus_timer);
 	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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-02  6:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26  6:51 [PATCH] wifi: rt2x00: prevent txstatus_timer rearm during USB uninitialize Bin Luo (University of Electronic Science and Technology of China)
2026-12-01 16:39 ` Stanislaw Gruszka
2026-12-02  6:06 ` Bin Luo (University of Electronic Science and Technology of China)

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.