Skip to contentSkip to conversation

can: raw: fix build without CONFIG_CAN_DEV

PATCH Superseded Oliver Hartkopp 1 participant 1 message Nov 27, 2025

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Oliver Hartkopp

author maintainer
#0 lore raw

PATCH v2 1/1 can: raw: fix build without CONFIG_CAN_DEV

The feature to instantly reject unsupported CAN frames makes use of CAN netdevice specific flags which are only accessible when the CAN device driver infrastructure is built.

Therefore check for CONFIG_CAN_DEV and fall back to MTU testing when the CAN device driver infrastructure is absent.

Fixes 1a620a723853 ("can: raw: instantly reject unsupported CAN frames")

---

v2: use #if IS_ENABLED(CONFIG_CAN_DEV) instead of #ifdev CONFIG_CAN_DEV

---
 net/can/raw.c | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)
net/can/raw.c +18 -14
index 223630f0f9e9..ccd93d3a6115 100644
@@ -890,62 +890,66 @@ static void raw_put_canxl_vcid(struct raw_sock *ro, struct sk_buff *skb)
 		cxl->prio &= CANXL_PRIO_MASK;
 		cxl->prio |= ro->tx_vcid_shifted;
 	}
 }
 
-static inline bool raw_dev_cc_enabled(struct net_device *dev,
-				      struct can_priv *priv)
+static bool raw_dev_cc_enabled(struct net_device *dev)
 {
+#if IS_ENABLED(CONFIG_CAN_DEV)
+	struct can_priv *priv = safe_candev_priv(dev);
+
 	/* The CANXL-only mode disables error-signalling on the CAN bus
 	 * which is needed to send CAN CC/FD frames
 	 */
 	if (priv)
 		return !can_dev_in_xl_only_mode(priv);
-
+#endif
 	/* virtual CAN interfaces always support CAN CC */
 	return true;
 }
 
-static inline bool raw_dev_fd_enabled(struct net_device *dev,
-				      struct can_priv *priv)
+static bool raw_dev_fd_enabled(struct net_device *dev)
 {
+#if IS_ENABLED(CONFIG_CAN_DEV)
+	struct can_priv *priv = safe_candev_priv(dev);
+
 	/* check FD ctrlmode on real CAN interfaces */
 	if (priv)
 		return (priv->ctrlmode & CAN_CTRLMODE_FD);
-
+#endif
 	/* check MTU for virtual CAN FD interfaces */
 	return (READ_ONCE(dev->mtu) >= CANFD_MTU);
 }
 
-static inline bool raw_dev_xl_enabled(struct net_device *dev,
-				      struct can_priv *priv)
+static bool raw_dev_xl_enabled(struct net_device *dev)
 {
+#if IS_ENABLED(CONFIG_CAN_DEV)
+	struct can_priv *priv = safe_candev_priv(dev);
+
 	/* check XL ctrlmode on real CAN interfaces */
 	if (priv)
 		return (priv->ctrlmode & CAN_CTRLMODE_XL);
-
+#endif
 	/* check MTU for virtual CAN XL interfaces */
 	return can_is_canxl_dev_mtu(READ_ONCE(dev->mtu));
 }
 
 static unsigned int raw_check_txframe(struct raw_sock *ro, struct sk_buff *skb,
 				      struct net_device *dev)
 {
-	struct can_priv *priv = safe_candev_priv(dev);
-
 	/* Classical CAN */
-	if (can_is_can_skb(skb) && raw_dev_cc_enabled(dev, priv))
+	if (can_is_can_skb(skb) && raw_dev_cc_enabled(dev))
 		return CAN_MTU;
 
 	/* CAN FD */
 	if (ro->fd_frames && can_is_canfd_skb(skb) &&
-	    raw_dev_fd_enabled(dev, priv))
+	    raw_dev_fd_enabled(dev))
 		return CANFD_MTU;
 
 	/* CAN XL */
 	if (ro->xl_frames && can_is_canxl_skb(skb) &&
-	    raw_dev_xl_enabled(dev, priv))
+	    raw_dev_xl_enabled(dev))
 		return CANXL_MTU;
 
 	return 0;
 }
 
Signature · 1 line
2.47.3