Linux wireless drivers development
 help / color / mirror / Atom feed
From: Ping-Ke Shih <pkshih@realtek.com>
To: Bitterblue Smith <rtl8821cerfe2@gmail.com>,
	"linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>
Cc: "i.mafifi17@gmail.com" <i.mafifi17@gmail.com>
Subject: RE: [PATCH rtw-next v3] wifi: rtw88: usb: Download the reserved page synchronously
Date: Wed, 16 Sep 2026 08:18:10 +0000	[thread overview]
Message-ID: <40bf5c51a1c24677bbd5e1ede8cbc5ce@realtek.com> (raw)
In-Reply-To: <5e0ce93e-0615-405e-956c-0f8dd8a543d9@gmail.com>

Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:
> @@ -499,16 +506,21 @@ static void rtw_usb_tx_queue_purge(struct rtw_usb *rtwusb)
> 
>  static void rtw_usb_write_port_complete(struct urb *urb)
>  {
> -       struct sk_buff *skb = urb->context;
> +       struct rtw_usb_write_data_cb *cb = urb->context;
> 

I think here is a racing with timeout case of wait_for_completion_timeout().

                           CPU0                      CPU1
           (rtw_usb_write_port_complete)         (rtw_usb_write_data)

           cb = urb->context
                                                wait_for_completion_timeout() timeout
                                                kfree(cb);
           cb->status = urb->status;
          (cb is free-after-use)

rtw89 handles this kind of problem by RCU. You can reference
rtw89_wait_for_cond_eval() to know how it does.

> -       dev_kfree_skb_any(skb);
> +       cb->status = urb->status;
> +       complete(&cb->done);
> +       dev_kfree_skb_any(cb->skb);
> +       if (!cb->sync)
> +               kfree(cb);
>  }
> 
>  static int rtw_usb_write_data(struct rtw_dev *rtwdev,
>                               struct rtw_tx_pkt_info *pkt_info,
> -                             u8 *buf)
> +                             u8 *buf, bool sync)
>  {
>         const struct rtw_chip_info *chip = rtwdev->chip;
> +       struct rtw_usb_write_data_cb *cb;
>         struct sk_buff *skb;
>         unsigned int size;
>         u8 qsel;
> @@ -528,11 +540,29 @@ static int rtw_usb_write_data(struct rtw_dev *rtwdev,
>         rtw_tx_fill_tx_desc(rtwdev, pkt_info, skb);
>         rtw_tx_fill_txdesc_checksum(rtwdev, pkt_info, skb->data);
> 
> +       cb = kmalloc_obj(*cb, GFP_KERNEL);
> +       if (!cb) {
> +               dev_kfree_skb_any(skb);
> +               return -ENOMEM;
> +       }
> +
> +       init_completion(&cb->done);
> +       cb->status = -EINPROGRESS;
> +       cb->skb = skb;
> +       cb->sync = sync;
> +
>         ret = rtw_usb_write_port(rtwdev, qsel, skb,
> -                                rtw_usb_write_port_complete, skb);
> +                                rtw_usb_write_port_complete, cb);
>         if (unlikely(ret)) {
>                 rtw_err(rtwdev, "failed to do USB write, ret=%d\n", ret);
>                 dev_kfree_skb_any(skb);
> +               kfree(cb);
> +       } else if (sync) {
> +               if (!wait_for_completion_timeout(&cb->done, secs_to_jiffies(5)))
> +                       ret = -ETIMEDOUT;
> +               else
> +                       ret = cb->status;
> +               kfree(cb);
>         }
> 
>         return ret;



  reply	other threads:[~2026-09-16  8:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-14 20:18 [PATCH rtw-next v3] wifi: rtw88: usb: Download the reserved page synchronously Bitterblue Smith
2026-09-16  8:18 ` Ping-Ke Shih [this message]
2026-09-16  9:00   ` Ping-Ke Shih

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=40bf5c51a1c24677bbd5e1ede8cbc5ce@realtek.com \
    --to=pkshih@realtek.com \
    --cc=i.mafifi17@gmail.com \
    --cc=linux-wireless@vger.kernel.org \
    --cc=rtl8821cerfe2@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