All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "YuanZhe Liu" <25031212351@stu.xidian.edu.cn>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH] USB: serial: f81534: fix write urb reuse while still in flight
Date: Mon, 30 Nov 2026 09:20:04 +0000	[thread overview]
Message-ID: <sashiko-outbox-240773@kernel.org> (raw)
In-Reply-To: <20261130090037.24537-1-25031212351@stu.xidian.edu.cn>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] USB: serial: f81534: race on tx_empty in
  f81534_submit_writer() stalls TX
--

commit e5c172675a1d26c17159432b9b68ed3d9a834936
Author: YuanZhe Liu <25031212351@stu.xidian.edu.cn>

USB: serial: f81534: fix write urb reuse while still in flight

This commit tracks whether the bulk-out write URB is active so that it is
only reused after its completion handler runs.

> diff --git a/drivers/usb/serial/f81534.c b/drivers/usb/serial/f81534.c
> index 8fc60c4d61660..13bd29d5075b5 100644
> --- a/drivers/usb/serial/f81534.c
> +++ b/drivers/usb/serial/f81534.c

[ ... ]

> @@ -517,12 +518,22 @@ static int f81534_submit_writer(struct usb_serial_port *port, gfp_t mem_flags)
>  	if (!test_and_clear_bit(F81534_TX_EMPTY_BIT, &port_priv->tx_empty))
>  		return 0;
>  
> +	/*
> +	 * The TX_EMPTY token only tells that the device drained its
> +	 * transmitter; the urb may still be owned by the HCD.
> +	 */
> +	if (test_and_set_bit(0, &port_priv->write_urb_active)) {
> +		set_bit(F81534_TX_EMPTY_BIT, &port_priv->tx_empty);
> +		return 0;
> +	}

[Severity: Medium]
Can clearing and restoring F81534_TX_EMPTY_BIT around the write_urb_active
check race with f81534_write_usb_callback() and stall TX?

f81534_submit_writer() drops port->lock before testing tx_empty and
write_urb_active.  If a caller finds write_urb_active set while the
in-flight URB completes on another CPU, both paths can exit without
submitting the next transfer:

CPU0                                  CPU1
f81534_submit_writer()
  test_and_clear_bit(..., &tx_empty)
  test_and_set_bit(..., &write_urb_active)
    /* returns 1, already active */
                                      f81534_write_usb_callback()
                                        clear_bit(..., &write_urb_active)
                                        f81534_submit_writer()
                                          test_and_clear_bit(..., &tx_empty)
                                            /* sees 0, returns 0 */
  set_bit(..., &tx_empty)
  return 0;                           <-- data stranded in write_fifo

With no URB in flight and no further TX_EMPTY notification coming from the
device, queued data remains stuck in port->write_fifo.

Conversely, if f81534_write() -> f81534_submit_writer() clears
F81534_TX_EMPTY_BIT and is interrupted before test_and_set_bit() by a
bulk-in completion receiving F81534_TOKEN_TX_EMPTY, the interrupt handler
sets F81534_TX_EMPTY_BIT, claims write_urb_active, and submits the URB.
When the interrupted context resumes, it sees write_urb_active set and
calls set_bit(F81534_TX_EMPTY_BIT, &port_priv->tx_empty) while the new
transfer is active, allowing f81534_write_usb_callback() to submit the
following URB before the device transmitter has drained.

Checking and updating tx_empty and write_urb_active under port->lock would
avoid both races.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130090037.24537-1-25031212351@stu.xidian.edu.cn?part=1

  reply	other threads:[~2026-11-30  9:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  9:00 [PATCH] USB: serial: f81534: fix write urb reuse while still in flight YuanZhe Liu
2026-11-30  9:20 ` sashiko-bot [this message]
2026-11-30 10:19 ` Greg Kroah-Hartman

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=sashiko-outbox-240773@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=25031212351@stu.xidian.edu.cn \
    --cc=linux-usb@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 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.