🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #5837

[PATCH v6] can: dev: can_fill_info(): don't wake up controller if interface is down

#5837
From: ChunYuZhiQiang
Date: Wed, 21 Oct 2026 02:33
114 lines
13388 bytes
If the interface is down, the CAN controller might be powered down, the
clock disabled, and/or its external reset asserted.

Don't call do_get_berr_counter() or do_get_auto_tdcv() to read the CAN
controller if the interface is down. This fixes a generic logic problem
that exists on all platforms.

As a result, IFLA_CAN_BERR_COUNTER is no longer reported for down
interfaces, and the automatic TDCV readback is skipped. The other TDC
parameters are still reported, as they are meaningful while the
interface is down. This is intentional: the counters and the automatic
TDCV are not meaningful in that state, and calling into the driver can
wake a runtime-suspended controller or touch registers whose clocks are
gated.

Fixes: ec56acfef2af1 ("can: flexcan: flexcan_get_berr_counter(): switch on clocks before accessing ecr register")
Cc: stable@vger.kernel.org
Signed-off-by: ChunYuZhiQiang <chunyuzhiqiang@yinhe.ht>
---
v6:
 - Only gate do_get_auto_tdcv() on netif_running(), as suggested by
   Vincent Mailhol and Marc Kleine-Budde. The other TDC parameters are
   still reported for down interfaces.
 - Adjust can_tdc_get_size() so that only the automatic TDCV size is
   skipped when the interface is down.
 - Keep the berr-counter gating unchanged.
---
 drivers/net/can/dev/netlink.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/net/can/dev/netlink.c b/drivers/net/can/dev/netlink.c
index 6f83b87d54fc..ae0cef791ef3 100644
--- a/drivers/net/can/dev/netlink.c
+++ b/drivers/net/can/dev/netlink.c
@@ -517,7 +517,7 @@ static int can_changelink(struct net_device *dev, struct nlattr *tb[],
 }
 
 static size_t can_tdc_get_size(struct data_bittiming_params *dbt_params,
-			       u32 tdc_flags)
+			       u32 tdc_flags, bool auto_tdcv_running)
 {
 	bool tdc_manual = tdc_flags & CAN_CTRLMODE_TDC_MANUAL_MASK;
 	size_t size;
@@ -538,7 +538,7 @@ static size_t can_tdc_get_size(struct data_bittiming_params *dbt_params,
 	}
 
 	if (tdc_flags) {
-		if (tdc_manual || dbt_params->do_get_auto_tdcv)
+		if (tdc_manual || (dbt_params->do_get_auto_tdcv && auto_tdcv_running))
 			size += nla_total_size(sizeof(u32));	/* IFLA_CAN_TDCV */
 		size += nla_total_size(sizeof(u32));		/* IFLA_CAN_TDCO */
 		if (dbt_params->tdc_const->tdcf_max)
@@ -548,8 +548,9 @@ static size_t can_tdc_get_size(struct data_bittiming_params *dbt_params,
 	return size;
 }
 
-static size_t can_data_bittiming_get_size(struct data_bittiming_params *dbt_params,
-					  u32 tdc_flags)
+static size_t
+can_data_bittiming_get_size(struct data_bittiming_params *dbt_params,
+			    u32 tdc_flags, bool auto_tdcv_running)
 {
 	size_t size = 0;
 
@@ -560,7 +561,8 @@ static size_t can_data_bittiming_get_size(struct data_bittiming_params *dbt_para
 	if (dbt_params->data_bitrate_const)		/* IFLA_CAN_DATA_BITRATE_CONST */
 		size += nla_total_size(sizeof(*dbt_params->data_bitrate_const) *
 				       dbt_params->data_bitrate_const_cnt);
-	size += can_tdc_get_size(dbt_params, tdc_flags);/* IFLA_CAN_TDC */
+
+	size += can_tdc_get_size(dbt_params, tdc_flags, auto_tdcv_running); /* IFLA_CAN_TDC */
 
 	return size;
 }
@@ -584,7 +586,7 @@ static size_t can_get_size(const struct net_device *dev)
 	size += nla_total_size(sizeof(u32));			/* IFLA_CAN_STATE */
 	size += nla_total_size(sizeof(struct can_ctrlmode));	/* IFLA_CAN_CTRLMODE */
 	size += nla_total_size(sizeof(u32));			/* IFLA_CAN_RESTART_MS */
-	if (priv->do_get_berr_counter)				/* IFLA_CAN_BERR_COUNTER */
+	if (priv->do_get_berr_counter && netif_running(dev))	/* IFLA_CAN_BERR_COUNTER */
 		size += nla_total_size(sizeof(struct can_berr_counter));
 	if (priv->termination_const) {
 		size += nla_total_size(sizeof(priv->termination));		/* IFLA_CAN_TERMINATION */
@@ -598,7 +600,8 @@ static size_t can_get_size(const struct net_device *dev)
 	size += can_ctrlmode_ext_get_size();			/* IFLA_CAN_CTRLMODE_EXT */
 
 	size += can_data_bittiming_get_size(&priv->fd,
-					    priv->ctrlmode & CAN_CTRLMODE_FD_TDC_MASK);
+					    priv->ctrlmode & CAN_CTRLMODE_FD_TDC_MASK,
+					    netif_running(dev));
 
 	return size;
 }
@@ -675,7 +678,7 @@ static int can_tdc_fill_info(struct sk_buff *skb, const struct net_device *dev,
 		if (tdc_manual) {
 			tdcv = tdc->tdcv;
 			err = 0;
-		} else if (dbt_params->do_get_auto_tdcv) {
+		} else if (dbt_params->do_get_auto_tdcv && netif_running(dev)) {
 			err = dbt_params->do_get_auto_tdcv(dev, &tdcv);
 		}
 		if (!err && nla_put_u32(skb, IFLA_CAN_TDC_TDCV, tdcv))
@@ -735,7 +738,7 @@ static int can_fill_info(struct sk_buff *skb, const struct net_device *dev)
 	    nla_put(skb, IFLA_CAN_CTRLMODE, sizeof(cm), &cm) ||
 	    nla_put_u32(skb, IFLA_CAN_RESTART_MS, priv->restart_ms) ||
 
-	    (priv->do_get_berr_counter &&
+	    (priv->do_get_berr_counter && netif_running(dev) &&
 	     !priv->do_get_berr_counter(dev, &bec) &&
 	     nla_put(skb, IFLA_CAN_BERR_COUNTER, sizeof(bec), &bec)) ||
 
-- 
2.47.3
Technical Details
Message-ID: <20261021023334.11803-1-chunyuzhiqiang@yinhe.ht>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-349726-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-349726-linux-kernel-netdev=dewy.ru
From: chunyuzhiqiang@yinhe.ht (ChunYuZhiQiang)
Newsgroups: linux.kernel.netdev
Subject: [PATCH v6] can: dev: can_fill_info(): don't wake up controller if interface is down
Date: Wed, 21 Oct 2026 10:33:34 +0800
Organization: Usenet Network
Message-ID: <20261021023334.11803-1-chunyuzhiqiang@yinhe.ht>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="4019604"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:tVN8SfD8YTIpLTvzLoYHtJ5iHo4= sha256:TewfQ/piiE7GOcx64djNLyLtF8uP3yTez6DNPchEARg=
	sha1:pSjvvnvovq9hrBg5h9Haa54KQJw= sha256:2EEosSdPkmVu00zhUJZ8PCmPa3gi2RZNda+Gn7aZRdw=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id BC9C3110EE6; Wed, 21 Oct 2026 05:37:49 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.148
X-Spam-Status: No, score=-3.148 tagged_above=-9999 required=6.31
	tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.25, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
	UNPARSEABLE_RELAY=0.001, URIBL_BLOCKED=0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=yinhe.ht
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id apqdjPp-npPB;
	Wed, 21 Oct 2026 05:37:46 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-349726-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=yinhe.ht
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 5C712110EBB; Wed, 21 Oct 2026 05:37:37 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 32D84612482; Wed, 21 Oct 2026 02:37:35 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1792550253;
	b=aaxY5/+b5pS8eVKdvni3MWUronBpIjljXVHICeqH/5l06PE+OCZgHp0Da/Yv6E5djIoy
	 BByJfr0HtBr5AfrTt0M47ya9IiWH2yr5+g2D+R1fl2439DqZPLx8CVZGRU/uWgQbWrqOd
	 kiug5z/e1+TtojZx93b1svch6wIWVHNDOXFerjAfxOc2vfMkxBRjVyUH2UACAZZzJHTdm
	 VItBe2ubte3OumetDuGp5Gs/9lHtWYb09ssM2OBWTf3uhGbcjyiwCQtZbISLcOweLQt24
	 /TpON8J8feCJr7Hn5+3PjKTD4H4dfULN1syOz0vpGg+f36E3bJopXlNUMdn27vWgQMQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792550253;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:
	 X-Alimail-AntiSpam:Received:From:To:Cc:Subject:Date:Message-ID:
	 X-Mailer:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=hDOM2tXalzzTZL+I3hmHPar7QZg9wO20POfFRI7De1o=;
	b=ey5Ia4y2+T41D5PEezThLOLZ25Z5jz9SZ0sHlmeXWXl9hHDl0wUIVjZY43wDry7w1f+R
	 HklRWT0JEt0jd/vsHKHH62Zufv5n4ISh7AFa7YQwH4d7xq/6B/o0awOdgzvLKHXmVjyu8
	 mSM5F1UdwewnB7ilTjQMuVCTXziz/k8qHLPWhAg+T1pXdkgIgAjHG1wjiO3jku4LxBtbI
	 IcSb38PnAyH1eirnAMPXlvIXCtvilOA7uGYjjzbQPJeBsJm2M7KT2jRQTkamtFIofX5fO
	 6mX6twKqoXbWsZDK2rpqdzMqAfT6hFbZrMdujC/wfhgXKrrpNWXoyJc4NFSMQJYJC8Q==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=yinhe.ht header.i=@yinhe.ht header.a=rsa-sha256 header.s=default header.b=jzAj9GUp;
	dmarc=none header.from=yinhe.ht;
	spf=pass smtp.mailfrom=yinhe.ht;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id DE99F606A32D;
	Wed, 21 Oct 2026 02:37:32 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=yinhe.ht header.i=@yinhe.ht header.a=rsa-sha256 header.s=default header.b=jzAj9GUp
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.28.195
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1792550252;
	b=VkrBaWitFCgrJ0V0MNkTqlbgycxu/pebg6z6bQiCtQ/SZhWZvupBmdsU/paA1z+r7Jeq
	 GBvpg83DEuJNxIi4LiVlfPg8pO/9vLx9QA0VD410D2IFBWyq8VQqf43iXc8gJLN2Fq41P
	 AJEH2UoyEpscwTPCUwgp0pKRax2xl37VL0vkNrSKpAE2LsRo7KgOPrT9Jcm+KClHuu6YB
	 1sKwNHdokZRv7SHpqAksGafnqhotk6lPUyWKdDJ/a8MSLNLZB8BtAwXFHSyYCNYfgd0Rf
	 yRu21cuI01R+iQNPpBfApyISmEZlUSr/1UIrAir0lHnwPPMgM0ZrSbIpWayZxnIptOg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792550252;
	h=DMARC-Filter:DKIM-Signature:X-Alimail-AntiSpam:Received:From:To:Cc:
	 Subject:Date:Message-ID:X-Mailer:MIME-Version:
	 Content-Transfer-Encoding;
	bh=hDOM2tXalzzTZL+I3hmHPar7QZg9wO20POfFRI7De1o=;
	b=e0gTUwKYINJp8Vpq1nnBw14h4HIKoe/xkUlzuf6Hv+KGCZ9oxXJUSSoUtt+EFfUQzJ7u
	 WToca+avaWxpsgr+FmiAC86mIHWEFxILSRFHVUKzxAf7YhUBz5b9/yPY7ACJBbhqSgiVr
	 SNd8U1cn2YxrBBIdY0+jXgg+M6Uy96tWAZq9kq/fu4RCg6hhdnS/YCdEawHNzIBSgqKNS
	 W+Bi/kfdfu+TMRfp9JPGzh8qhXZ/djpK220pL05zCJIHxi425By6Fc5+OzsCOSKrv2Pho
	 gkQoALGrlVcLyGrdcLxxTdUmHJKRkI/BNHcp3/TVPIRJjlgNxasoO2ADK9Snnallcxw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=none header.from=yinhe.ht;
	spf=pass smtp.mailfrom=yinhe.ht;
	dkim=pass header.d=yinhe.ht header.i=@yinhe.ht header.a=rsa-sha256 header.s=default header.b=jzAj9GUp;
	arc=none smtp.remote-ip=115.124.28.195
X-Received: from out28-195.mail.aliyun.com (out28-195.mail.aliyun.com [115.124.28.195])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3CDB606A31F;
	Wed, 21 Oct 2026 02:37:29 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D3CDB606A31F
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=yinhe.ht
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yinhe.ht
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=yinhe.ht; s=default;
	t=1792550248; h=From:To:Subject:Date:Message-ID:MIME-Version;
	bh=hDOM2tXalzzTZL+I3hmHPar7QZg9wO20POfFRI7De1o=;
	b=jzAj9GUpkK5ZaVgQw2qkT5hRb8hXrzxHB8L+OQRDrNiboMf5foVQAyZPUlNlFOIJZJppCcfThSXv0T981wL6sffXIeUEfQ1KVXXPTeMoLGh+OZAnDAvovaOqhia2diBfmAwvySp/YV2a5vELPTWIEToNEpAp45m2QmMTqVvCP3UOto/QsWuv3e7EBc9lRJjcP454vKqX5MUxKsOetSUgSkSRm25+92u3W/5peWUCpy0aVxyeme7u3Q5Qn+UJlcd7Um48g5ww6s5MuM4p37HTRn6IdYGoQxGc1B5bgl7XFCgYRui9HSlbkcLaa5LVqC2yCgUXbaTIDnvRrDQbjjL4Xw==
X-Alimail-AntiSpam: AC=CONTINUE;BC=0.07436261|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_system_inform|0.0253096-0.00470234-0.969988;FP=2915779513016650645|0|0|0|0|-1|-1|-1;HT=maildocker-contentspam033037028158;MF=chunyuzhiqiang@yinhe.ht;NM=1;PH=DS;RN=10;RT=10;SR=0;TI=SMTPD_---.jm9xUvS_1792550246;
X-Received: from galx..(mailfrom:chunyuzhiqiang@yinhe.ht fp:SMTPD_---.jm9xUvS_1792550246 cluster:ay29)
          by smtp.aliyun-inc.com;
          Wed, 21 Oct 2026 10:37:27 +0800
X-Cc: netdev@vger.kernel.org,
	linux-can@vger.kernel.org,
	mkl@pengutronix.de,
	kernel@pengutronix.de,
	haibo.chen@oss.nxp.com,
	shawnguo@kernel.org,
	imx@lists.linux.dev,
	stable@vger.kernel.org,
	ChunYuZhiQiang <chunyuzhiqiang@yinhe.ht>
X-Mailer: git-send-email 2.47.3
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list