Linux USB
 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: cypress_m8: fix write URB double-submission race
Date: Sat, 05 Dec 2026 17:16:20 +0000	[thread overview]
Message-ID: <sashiko-outbox-251760@kernel.org> (raw)
In-Reply-To: <20261205170022.4906-1-25031212351@stu.xidian.edu.cn>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] usb: serial: cypress_m8: TX stall and lost cmd_ctrl race in
  cypress_send()
--

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

USB: serial: cypress_m8: fix write URB double-submission race

This commit sets priv->write_urb_in_use while checking it in
cypress_send() instead of waiting until the send label, and clears it
again if kfifo_out_locked() finds no data to transmit.

> diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
> index bd9b68b691de6..7b6cb9a04e41e 100644
> --- a/drivers/usb/serial/cypress_m8.c
> +++ b/drivers/usb/serial/cypress_m8.c
> @@ -703,6 +703,7 @@ static void cypress_send(struct usb_serial_port *port)
>  		spin_unlock_irqrestore(&priv->lock, flags);
>  		return;
>  	}
> +	priv->write_urb_in_use = 1;
>  	spin_unlock_irqrestore(&priv->lock, flags);
>  
>  	/* clear buffer */
> @@ -739,8 +740,12 @@ static void cypress_send(struct usb_serial_port *port)
>  					&port->interrupt_out_buffer[offset],
>  					port->interrupt_out_size - offset,
>  					&priv->lock);
> -	if (count == 0)
> +	if (count == 0) {
> +		spin_lock_irqsave(&priv->lock, flags);
> +		priv->write_urb_in_use = 0;
> +		spin_unlock_irqrestore(&priv->lock, flags);
>  		return;
> +	}
>  
>  	switch (priv->pkt_fmt) {
>  	default:

[Severity: High]
Does this introduce a lost-wakeup race that leaves TX data stranded in
priv->write_fifo?

CPU0                                CPU1
cypress_write_int_callback()
  cypress_send()
    lock(&priv->lock)
    priv->write_urb_in_use = 1
    unlock(&priv->lock)
    ...
    kfifo_out_locked(...) == 0
                                    cypress_write()
                                      kfifo_in_locked(...)
                                      cypress_send()
                                        lock(&priv->lock)
                                        write_urb_in_use != 0  <-- returns
                                        unlock(&priv->lock)
    lock(&priv->lock)
    priv->write_urb_in_use = 0
    unlock(&priv->lock)
    return  <-- TX data stranded

Because priv->lock is dropped before clearing priv->write_urb_in_use, CPU1
assumes an in-flight URB callback will drain the FIFO and returns early.
CPU0 then returns without submitting an URB, leaving the queued bytes
stranded indefinitely and hanging tcdrain() or port close.

The same window between checking priv->cmd_ctrl and clearing
priv->write_urb_in_use can also strand a concurrent line-control update
(such as from cypress_tiocmset()) with priv->cmd_ctrl left at 1 and no
URB in flight.

Holding priv->lock continuously across checking priv->write_urb_in_use,
checking priv->cmd_ctrl, and draining priv->write_fifo with kfifo_out(),
setting priv->write_urb_in_use = 1 only when there is work to submit,
would avoid both double submission and this stall.

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

      reply	other threads:[~2026-12-05 17:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05 17:00 [PATCH] USB: serial: cypress_m8: fix write URB double-submission race YuanZhe Liu
2026-12-05 17:16 ` sashiko-bot [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=sashiko-outbox-251760@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox