From nobody Sat Jul 25 03:45:58 2026 Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D0DFCA5A for ; Sun, 19 Jul 2026 03:00:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784430033; cv=none; b=LHTvfy2dAJkvdq0sFMmoAhH9o2f3ay6NwpxdJON/9/MZqCXGbD4lroJkyEintNpYPJBt0QgDINTjBmrwmBunizgokd/22cx/lz3ahPXWW7Ff9Cm2cHJz5cGA4x5/nsttVUA6lUuSsBZdaTZACY77aWUoSkiHE7lNTbxATnwln34= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784430033; c=relaxed/simple; bh=Jn33P+/6FTfvH5tB+4YcYehstSunwoyd5SiHVTVlZz8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jkqf/IMeT7y/6A0r/3Xry61A/KRBR/OLANPalBEfBPrVek8tiUMEJ8CftPb5qVxjuXc2dTrV0uZgrvadExr/P1r5HQVnudBxcDYLi6tUqcqcl9bmJZoBIJ/HXLl9x+VsTWDnCX7pcinAIiR0swVPS/GswQ/W25kGuosVyEmRf3U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lI8NQ+Rr; arc=none smtp.client-ip=209.85.160.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lI8NQ+Rr" Received: by mail-qt1-f177.google.com with SMTP id d75a77b69052e-51c08df8513so38906601cf.3 for ; Sat, 18 Jul 2026 20:00:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784430031; x=1785034831; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=8VKY6n6oODsytlm7jYrsNeF3Lue+neWZnZVfcsQNCPs=; b=lI8NQ+Rrnf8oYxMmCdApHmFEb48jlzs0LGnVeIjLNjlsDTJAa5bdBfkZ6QR6ZY5C8b pXto3JwD1OFkVOEc9DrNlMuM08uxAUDjJaQ8E6TvnMPDLOsdgLmUmOt5U09PUWlANSNs sFCjGuGPHLm7YkpwuYsUkN74Flnow14E4YaCyJVqM18a/9oELx9o4J25l8fDZCeYrz4Q 98ZB6fGUJ2joROmVyIv+4gvJQMrYPkp5onykkeROLla5yeVCENZbxyF47eINYGksBaEb IESWxv6bIZnqcfVLMIUC6pXI0l0rgVaO1XIvPaFItnbuvI9YJmQjitWMx4HG1zmM2ICe 5ZCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784430031; x=1785034831; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=8VKY6n6oODsytlm7jYrsNeF3Lue+neWZnZVfcsQNCPs=; b=AHbT5Xea7pzT4JzraUl8weJ6S0InquZUPZH04cSI43aaPidh2kNKq1TmVLKwweEN3d m6WkOUrudZX+fr1ijOT9jnb/OFLKgRI+S5kDOssUIS5UvenWKzXspjaYGReCmTbWdYU4 RIQdofkLacVk2zjBdvA8Q8U9MQWEbPoDsLGUbZixx56hgdaqZITo6rJct/u8J66IyueW k4G3g6iBBJRbqinX13pwFR2acCwnXbHir1oRUT34F3VHZ16jPoh5MCj1FtnhTWb3OgKU G93b5i71RGR87R5W4eKvRAG+pp5Fbz4WlnWNA/1D67dZaKMb8Q25Rq6tGFv8GhoiqWO6 eFqA== X-Forwarded-Encrypted: i=1; AHgh+RpejUde29MzlR8fEovXx0DbaKhmfFIDqzK+2OzAMCybRifsBC6udvxcgCb2av6zIUamm+h6XLJN+lWZOwM=@vger.kernel.org X-Gm-Message-State: AOJu0YxSGSn3grIkL0tOas3ywQesHro66YyGVXity/LTUuTk4a6wPbCC QYVF/z2NV/AKsNgeB1XgPt7BDeERpYPp2MV4FqzGDYIoTaWEFl5AyBvs X-Gm-Gg: AfdE7cn2Sa91XnmnB7as2PoVBeGYfLTA08OTZRyaJ0nQ7pafVY9fODN8k1bzxgWwimg j4uhMy7xQlaMOenGsZF0g5jFWYHBGsFRbL4n4yVEYQLrlBELB18bBuA7KOJi/Bn4ajZG87vKDoV u6NK7RifYhoY8UV6DOU8B9OZyXXrKOYYdWEkJPFNOobuesTNsZFiLHFYoM14a8DmHp1YBflH3mU SW2vBR4EptXPPMRyA41W2X65pGE0CK5fh7HnNnSz8vIgNso7pq2PDpsvOnXvPRoi3l83fsLCdv5 r4OcGLMBlosknSjkKhtUyDgftNN9YhVQ+eSAnz8rmOhQLn/KZvvqvJpDCdFrsGe002XMXt9yFQf rQp2iU3Gs+ltpuw9I8YKIMFhAAN+XwlmVt4DnBclG+HnZBV7rUQwUNC1Yk1kmC+juIyeJ5f75mn TYapJLt8gefOHlJ5lot8H2ns766et4ouM= X-Received: by 2002:ac8:5e49:0:b0:51c:7b12:1202 with SMTP id d75a77b69052e-5213f36fceamr85793061cf.80.1784430031320; Sat, 18 Jul 2026 20:00:31 -0700 (PDT) Received: from i4-l-hqh5357-03.ad.psu.edu ([130.203.139.71]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-5214f01654fsm44853871cf.19.2026.07.18.20.00.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jul 2026 20:00:30 -0700 (PDT) From: Shuangpeng Bai To: Marc Kleine-Budde , Vincent Mailhol Cc: Vadim Fedorenko , Celeste Liu , Kees Cook , linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, Shuangpeng Bai , stable@vger.kernel.org Subject: [PATCH can v2] can: gs_usb: fix hardware timestamp state for mixed channels Date: Sat, 18 Jul 2026 23:00:00 -0400 Message-ID: <20260719030000.3667449-1-shuangpeng.kernel@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260718052815.2507496-1-shuangpeng.kernel@gmail.com> References: <20260718052815.2507496-1-shuangpeng.kernel@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The hardware timestamp state is shared by struct gs_usb, but gs_can_open() and gs_can_close() tie its initialization and teardown to active_channels and to the feature bits of the channel being opened or closed. This is wrong for mixed-channel devices in both directions. If a non-timestamp channel opens first, a later timestamp-capable channel does not initialize the shared cyclecounter/timecounter because active_channels is already non-zero. Timestamp RX then calls timecounter_cyc2time() with parent->tc.cc unset. Conversely, if a timestamp-capable channel opens first and starts the shared delayed work, then closes while a non-timestamp channel remains active, disconnect may close the non-timestamp channel last. The old teardown check skips gs_usb_timestamp_stop() in that case and frees struct gs_usb while the delayed work timer is still queued. Count the number of active timestamp-capable channels. Start the shared timestamp worker when the first such channel opens, stop it when the last such channel closes, and unwind the count if open fails. Fixes: 45dfa45f52e6 ("can: gs_usb: add RX and TX hardware timestamp support= ") Cc: stable@vger.kernel.org Suggested-by: Vadim Fedorenko Signed-off-by: Shuangpeng Bai --- Changes in v2: - Count active timestamp-capable channels instead of tracking only whether the shared timestamp worker has been started. - Stop the shared timestamp worker when the last timestamp-capable channel closes, even if non-timestamp channels remain open. - Unwind the timestamp-capable channel count on gs_can_open() failures. drivers/net/can/usb/gs_usb.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c index ec9a7cbbbc69..9cc197803e0d 100644 --- a/drivers/net/can/usb/gs_usb.c +++ b/drivers/net/can/usb/gs_usb.c @@ -337,6 +337,7 @@ struct gs_usb { =20 unsigned int hf_size_rx; u8 active_channels; + u8 active_timestamp_channels; u8 channel_cnt; =20 unsigned int pipe_in; @@ -980,10 +981,13 @@ static int gs_can_open(struct net_device *netdev) =20 can_rx_offload_enable(&dev->offload); =20 - 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++; + } =20 + if (!parent->active_channels) { for (i =3D 0; i < GS_MAX_RX_URBS; i++) { u8 *buf; =20 @@ -1094,13 +1098,15 @@ static int gs_can_open(struct net_device *netdev) out_usb_free_urb: usb_free_urb(urb); out_usb_kill_anchored_urbs: - if (!parent->active_channels) { - usb_kill_anchored_urbs(&parent->rx_submitted); - - if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP) + if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP) { + parent->active_timestamp_channels--; + if (!parent->active_timestamp_channels) gs_usb_timestamp_stop(parent); } =20 + if (!parent->active_channels) + usb_kill_anchored_urbs(&parent->rx_submitted); + can_rx_offload_disable(&dev->offload); close_candev(netdev); =20 @@ -1152,13 +1158,15 @@ static int gs_can_close(struct net_device *netdev) =20 /* Stop polling */ parent->active_channels--; - if (!parent->active_channels) { - usb_kill_anchored_urbs(&parent->rx_submitted); - - if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP) + if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP) { + parent->active_timestamp_channels--; + if (!parent->active_timestamp_channels) gs_usb_timestamp_stop(parent); } =20 + if (!parent->active_channels) + usb_kill_anchored_urbs(&parent->rx_submitted); + /* Stop sending URBs */ usb_kill_anchored_urbs(&dev->tx_submitted); atomic_set(&dev->active_tx_urbs, 0); --=20 2.43.0