Linux wireless drivers development
 help / color / mirror / Atom feed
From: Stanislaw Gruszka <stf_xl@wp.pl>
To: "Bin Luo (University of Electronic Science and Technology of
	China)" <luob87709@gmail.com>
Cc: johannes@sipsolutions.net, linux-wireless@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] wifi: rt2x00: prevent txstatus_timer rearm during USB uninitialize
Date: Tue, 1 Dec 2026 17:39:41 +0100	[thread overview]
Message-ID: <aw74TesphbfOjFdW@wp.pl> (raw)
In-Reply-To: <20261126065132.971-1-luob87709@gmail.com>

Hi,

On Thu, Nov 26, 2026 at 02:51:32PM +0800, Bin Luo (University of Electronic Science and Technology of China) wrote:
> 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

This is under condition:

  if (rt2800_txstatus_pending(rt2x00dev))

which should be false at this point, or I missed something?

Regards
Stanislaw

> 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
> 

      reply	other threads:[~2026-12-01 16:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

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=aw74TesphbfOjFdW@wp.pl \
    --to=stf_xl@wp.pl \
    --cc=johannes@sipsolutions.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=luob87709@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox