From: Dan Carpenter <dan.carpenter@linaro.org>
To: Prashanth K <prashanth.k@oss.qualcomm.com>
Cc: linux-usb@vger.kernel.org
Subject: [bug report] usb: gadget: u_serial: Avoid double unlock of serial_port_lock
Date: Mon, 26 May 2025 14:12:43 +0300 [thread overview]
Message-ID: <aDRMq88_LjlnKIQe@stanley.mountain> (raw)
Hello Prashanth K,
Commit 1c06aff9b82f ("usb: gadget: u_serial: Avoid double unlock of
serial_port_lock") from May 6, 2025 (linux-next), leads to the
following Smatch static checker warning:
drivers/usb/gadget/function/u_serial.c:1511 gserial_suspend()
warn: duplicate check 'port' (previous on line 1498)
drivers/usb/gadget/function/u_serial.c
1490 void gserial_suspend(struct gserial *gser)
1491 {
1492 struct gs_port *port;
1493 unsigned long flags;
1494
1495 spin_lock_irqsave(&serial_port_lock, flags);
1496 port = gser->ioport;
1497
1498 if (!port) {
1499 spin_unlock_irqrestore(&serial_port_lock, flags);
1500 return;
1501 }
1502
1503 if (port->write_busy || port->write_started) {
1504 /* Wakeup to host if there are ongoing transfers */
1505 spin_unlock_irqrestore(&serial_port_lock, flags);
1506 if (!gserial_wakeup_host(gser))
1507 return;
1508
1509 /* Check if port is valid after acquiring lock back */
I should have caught this in review but this comment doesn't make sense.
"port" is a local variable so it's going to be non-NULL.
1510 spin_lock_irqsave(&serial_port_lock, flags);
Maybe we should re-assign it? "port = gser->ioport;" before the NULL
check? Otherwise we could just delete the NULL check.
1511 if (!port) {
1512 spin_unlock_irqrestore(&serial_port_lock, flags);
1513 return;
1514 }
1515 }
1516
1517 spin_lock(&port->port_lock);
1518 spin_unlock(&serial_port_lock);
1519 port->suspended = true;
1520 port->start_delayed = true;
1521 spin_unlock_irqrestore(&port->port_lock, flags);
1522 }
regards,
dan carpenter
next reply other threads:[~2025-05-26 11:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-26 11:12 Dan Carpenter [this message]
2025-06-17 11:51 ` [bug report] usb: gadget: u_serial: Avoid double unlock of serial_port_lock Prashanth K
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=aDRMq88_LjlnKIQe@stanley.mountain \
--to=dan.carpenter@linaro.org \
--cc=linux-usb@vger.kernel.org \
--cc=prashanth.k@oss.qualcomm.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