[PATCH net 3/9] can: netlink: fix static FD-NON-ISO mode validation

From
Marc Kleine-Budde <mkl@pengutronix.de>
Date
2026-11-15 09:57:52
Also in
linux-can, stable
Reply to
Marc Kleine-Budde, 2026-11-15
From: Zhu Ling <redacted>

The static CAN_CTRLMODE_FD_NON_ISO mode does not have to be specified when
CAN FD is disabled. Since commit 6742ca18cb41 ("can: netlink: add userland
error messages"), ctrlstatic_missing is calculated before applying this
exception. Disabling CAN FD on a controller with static FD-NON-ISO mode
therefore fails with -EOPNOTSUPP.

Apply the exception to ctrlstatic_missing instead of modifying ctrlstatic.
Keep the original static mode mask and restore it after applying the
userspace mask, so a request that disables CAN FD cannot remove
CAN_CTRLMODE_FD_NON_ISO from priv->ctrlmode.

Fixes: 6742ca18cb41 ("can: netlink: add userland error messages")
Cc: <redacted>
Signed-off-by: Zhu Ling <redacted>
Reviewed-by: Marc Kleine-Budde <mkl@pengutronix.de>
Link: https://patch.msgid.link/tencent_3A964832542399A780E646D6A6246335C409@qq.com (local)
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---

Notes:
    FAQ:
    
    Q: What about netlink payload size underestimation in can_get_size() for
       the IFLA_CAN_BITRATE_MAX attribute.
    A: This issue will be fixed in a follow up patch, to ease backporting to
       stable.
    
    Q: What about netlink payload size underestimation in `can_pwm_get_size()`
       when PWM capabilities exist but `CAN_CTRLMODE_XL_TMS` is disabled?
    A: This issue will be fixed in a follow up patch, to ease backporting to
       stable.

 drivers/net/can/dev/netlink.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/net/can/dev/netlink.c b/drivers/net/can/dev/netlink.c
index 081dfddda000..0cd55613a616 100644
--- a/drivers/net/can/dev/netlink.c
+++ b/drivers/net/can/dev/netlink.c
@@ -332,7 +332,7 @@ static int can_ctrlmode_changelink(struct net_device *dev,
 
 	/* do not check for static fd-non-iso if 'fd' is disabled */
 	if (!(maskedflags & CAN_CTRLMODE_FD))
-		ctrlstatic &= ~CAN_CTRLMODE_FD_NON_ISO;
+		ctrlstatic_missing &= ~CAN_CTRLMODE_FD_NON_ISO;
 
 	if (ctrlstatic_missing) {
 		NL_SET_ERR_MSG_FMT(extack,
@@ -357,9 +357,9 @@ static int can_ctrlmode_changelink(struct net_device *dev,
 		priv->ctrlmode &= ~(CAN_CTRLMODE_XL_TDC_MASK |
 				    CAN_CTRLMODE_XL_TMS);
 
-	/* clear bits to be modified and copy the flag values */
+	/* clear bits to be modified, copy flags and restore static modes */
 	priv->ctrlmode &= ~cm->mask;
-	priv->ctrlmode |= maskedflags;
+	priv->ctrlmode |= maskedflags | ctrlstatic;
 
 	/* Wipe potential leftovers from previous CAN FD/XL config */
 	if (!(priv->ctrlmode & CAN_CTRLMODE_FD)) {
-- 
2.53.0
Thread (14 messages) 14 messages, 3 authors, last reply 1d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help