* [net-next v2] can: raw: fix build without CONFIG_CAN_DEV
@ 2025-11-27 22:32 Oliver Hartkopp
0 siblings, 0 replies; only message in thread
From: Oliver Hartkopp @ 2025-11-27 22:32 UTC (permalink / raw)
To: linux-can
Cc: netdev, davem, kuba, kernel, mkl, Oliver Hartkopp,
Vincent Mailhol
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")
Reported-by: Vincent Mailhol <mailhol@kernel.org>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
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(-)
diff --git a/net/can/raw.c b/net/can/raw.c
index 223630f0f9e9..ccd93d3a6115 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -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;
}
--
2.47.3
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2025-11-27 22:32 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-27 22:32 [net-next v2] can: raw: fix build without CONFIG_CAN_DEV Oliver Hartkopp
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).