From: sashiko-bot@kernel.org
To: "Shuangpeng Bai" <shuangpeng.kernel@gmail.com>
Cc: "Vincent Mailhol" <mailhol@kernel.org>,
"Oleksij Rempel" <o.rempel@pengutronix.de>,
"Marc Kleine-Budde" <mkl@pengutronix.de>,
"Oliver Hartkopp" <socketcan@hartkopp.net>,
linux-can@vger.kernel.org
Subject: Re: [PATCH can v2] can: gs_usb: fix hardware timestamp state for mixed channels
Date: Sun, 19 Jul 2026 03:13:49 +0000 [thread overview]
Message-ID: <20260719031349.BD0CA1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260719030000.3667449-1-shuangpeng.kernel@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Data race and lock corruption due to unprotected initialization of shared timestamp lock
--
--- Patch [1]: [PATCH can v2] can: gs_usb: fix hardware timestamp state for mixed channels ---
commit 5294b98eba495191f8e49a8e183658cbb1702465
Author: Shuangpeng Bai <shuangpeng.kernel@gmail.com>
can: gs_usb: fix hardware timestamp state for mixed channels
This patch decouples the hardware timestamp state from active_channels. It
tracks timestamp-capable channels separately to fix initialization for
mixed-channel devices.
> diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
> index ec9a7cbbbc696..9cc197803e0d7 100644
> --- a/drivers/net/can/usb/gs_usb.c
> +++ b/drivers/net/can/usb/gs_usb.c
[ ... ]
> @@ -980,10 +981,13 @@ static int gs_can_open(struct net_device *netdev)
>
> can_rx_offload_enable(&dev->offload);
>
> - if (!parent->active_channels) {
> - if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP)
> + if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP) {
> + if (!parent->active_timestamp_channels)
> gs_usb_timestamp_init(parent);
> + parent->active_timestamp_channels++;
> + }
>
> + if (!parent->active_channels) {
> for (i = 0; i < GS_MAX_RX_URBS; i++) {
> u8 *buf;
[Severity: High]
Can this corrupt the tc_lock spinlock if an RX callback executes concurrently?
Since gs_usb_timestamp_init() is now called independently of
!parent->active_channels, it can execute while RX URBs are already polling (if
a non-timestamp channel was opened first).
gs_usb_timestamp_init() re-initializes the lock and timecounter:
spin_lock_init(&parent->tc_lock);
spin_lock_bh(&parent->tc_lock);
timecounter_init(&parent->tc, &parent->cc, ktime_get_real_ns());
If a USB device injects an RX frame during this window, the active RX URB
completion handler (gs_usb_receive_bulk_callback) can process it. Because
__dev_open() sets __LINK_STATE_START before calling ndo_open(), the
netif_running() check in the callback will pass, and
gs_usb_skb_set_timestamp() could attempt to acquire parent->tc_lock at the
same time it is being re-initialized.
Is there a way to safely initialize this lock before URBs are active, or
initialize it only once during device probe?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260719030000.3667449-1-shuangpeng.kernel@gmail.com?part=1
next prev parent reply other threads:[~2026-07-19 3:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-18 5:28 [PATCH can] can: gs_usb: fix hardware timestamp state for mixed channels Shuangpeng Bai
2026-07-18 5:42 ` sashiko-bot
2026-07-18 21:53 ` Vadim Fedorenko
2026-07-19 3:00 ` [PATCH can v2] " Shuangpeng Bai
2026-07-19 3:13 ` sashiko-bot [this message]
2026-07-19 9:25 ` Vadim Fedorenko
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=20260719031349.BD0CA1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=mailhol@kernel.org \
--cc=mkl@pengutronix.de \
--cc=o.rempel@pengutronix.de \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shuangpeng.kernel@gmail.com \
--cc=socketcan@hartkopp.net \
/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