From: Oliver Hartkopp <socketcan@hartkopp.net>
To: linux-can@vger.kernel.org
Cc: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org,
kernel@pengutronix.de, mkl@pengutronix.de,
Oliver Hartkopp <socketcan@hartkopp.net>,
Vincent Mailhol <mailhol@kernel.org>
Subject: [net-next] can: raw: fix build without CONFIG_CAN_DEV
Date: Thu, 27 Nov 2025 22:07:10 +0100 [thread overview]
Message-ID: <20251127210710.25800-1-socketcan@hartkopp.net> (raw)
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>
---
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..9d5c43df06dd 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)
{
+#ifdef 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)
{
+#ifdef 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)
{
+#ifdef 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
next reply other threads:[~2025-11-27 21:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-27 21:07 Oliver Hartkopp [this message]
2025-11-27 22:22 ` [net-next] can: raw: fix build without CONFIG_CAN_DEV Marc Kleine-Budde
2025-11-27 22:35 ` Oliver Hartkopp
2025-11-27 22:43 ` Marc Kleine-Budde
2025-11-27 23:03 ` Oliver Hartkopp
2025-11-27 23:24 ` Oliver Hartkopp
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251127210710.25800-1-socketcan@hartkopp.net \
--to=socketcan@hartkopp.net \
--cc=davem@davemloft.net \
--cc=kernel@pengutronix.de \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=mailhol@kernel.org \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).