* [net-next] can: raw: fix build without CONFIG_CAN_DEV
@ 2025-11-27 21:07 Oliver Hartkopp
2025-11-27 22:22 ` Marc Kleine-Budde
0 siblings, 1 reply; 6+ messages in thread
From: Oliver Hartkopp @ 2025-11-27 21:07 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>
---
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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [net-next] can: raw: fix build without CONFIG_CAN_DEV
2025-11-27 21:07 [net-next] can: raw: fix build without CONFIG_CAN_DEV Oliver Hartkopp
@ 2025-11-27 22:22 ` Marc Kleine-Budde
2025-11-27 22:35 ` Oliver Hartkopp
0 siblings, 1 reply; 6+ messages in thread
From: Marc Kleine-Budde @ 2025-11-27 22:22 UTC (permalink / raw)
To: Oliver Hartkopp; +Cc: linux-can, netdev, davem, kuba, kernel, Vincent Mailhol
[-- Attachment #1: Type: text/plain, Size: 1678 bytes --]
On 27.11.2025 22:07:10, Oliver Hartkopp wrote:
> 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>
That's not sufficient. We can build the CAN_DEV as a module but compile
CAN_RAW into the kernel.
This patch does the same as your's but only with a single ifdef in the
header file.
diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
index 52c8be5c160e..14d58461430e 100644
--- a/include/linux/can/dev.h
+++ b/include/linux/can/dev.h
@@ -111,7 +111,14 @@ struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max,
void free_candev(struct net_device *dev);
/* a candev safe wrapper around netdev_priv */
+#ifdef CONFIG_CAN_DEV
struct can_priv *safe_candev_priv(struct net_device *dev);
+#else
+static inline struct can_priv *safe_candev_priv(struct net_device *dev)
+{
+ return NULL;
+}
+#endif
int open_candev(struct net_device *dev);
void close_candev(struct net_device *dev);
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung Nürnberg | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [net-next] can: raw: fix build without CONFIG_CAN_DEV
2025-11-27 22:22 ` Marc Kleine-Budde
@ 2025-11-27 22:35 ` Oliver Hartkopp
2025-11-27 22:43 ` Marc Kleine-Budde
0 siblings, 1 reply; 6+ messages in thread
From: Oliver Hartkopp @ 2025-11-27 22:35 UTC (permalink / raw)
To: Marc Kleine-Budde; +Cc: linux-can, netdev, davem, kuba, kernel, Vincent Mailhol
On 27.11.25 23:22, Marc Kleine-Budde wrote:
> On 27.11.2025 22:07:10, Oliver Hartkopp wrote:
>> 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>
>
> That's not sufficient. We can build the CAN_DEV as a module but compile
> CAN_RAW into the kernel.
Oh, yes that's better.
I had a fight with CONFIG_CAN_DEV with my first patch too.
That's why I sent a v2 some seconds ago.
>
> This patch does the same as your's but only with a single ifdef in the
> header file.
>
> diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
> index 52c8be5c160e..14d58461430e 100644
> --- a/include/linux/can/dev.h
> +++ b/include/linux/can/dev.h
> @@ -111,7 +111,14 @@ struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max,
> void free_candev(struct net_device *dev);
>
> /* a candev safe wrapper around netdev_priv */
> +#ifdef CONFIG_CAN_DEV
> struct can_priv *safe_candev_priv(struct net_device *dev);
> +#else
> +static inline struct can_priv *safe_candev_priv(struct net_device *dev)
> +{
> + return NULL;
> +}
> +#endif
Will send a v3 with your suggestion.
Many thanks,
Oliver
>
> int open_candev(struct net_device *dev);
> void close_candev(struct net_device *dev);
>
> Marc
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [net-next] can: raw: fix build without CONFIG_CAN_DEV
2025-11-27 22:35 ` Oliver Hartkopp
@ 2025-11-27 22:43 ` Marc Kleine-Budde
2025-11-27 23:03 ` Oliver Hartkopp
0 siblings, 1 reply; 6+ messages in thread
From: Marc Kleine-Budde @ 2025-11-27 22:43 UTC (permalink / raw)
To: Oliver Hartkopp; +Cc: linux-can, netdev, davem, kuba, kernel, Vincent Mailhol
[-- Attachment #1: Type: text/plain, Size: 623 bytes --]
On 27.11.2025 23:35:48, Oliver Hartkopp wrote:
> > That's not sufficient. We can build the CAN_DEV as a module but compile
> > CAN_RAW into the kernel.
> Oh, yes that's better.
It's nicer, but it will not work if you build CAN_RAW into the kernel
and CAN_DEV as a module....Let me think of the right kconfig magic to
workaround this...
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung Nürnberg | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [net-next] can: raw: fix build without CONFIG_CAN_DEV
2025-11-27 22:43 ` Marc Kleine-Budde
@ 2025-11-27 23:03 ` Oliver Hartkopp
2025-11-27 23:24 ` Oliver Hartkopp
0 siblings, 1 reply; 6+ messages in thread
From: Oliver Hartkopp @ 2025-11-27 23:03 UTC (permalink / raw)
To: Marc Kleine-Budde; +Cc: linux-can, netdev, davem, kuba, kernel, Vincent Mailhol
Hello Marc,
On 27.11.25 23:43, Marc Kleine-Budde wrote:
> On 27.11.2025 23:35:48, Oliver Hartkopp wrote:
>>> That's not sufficient. We can build the CAN_DEV as a module but compile
>>> CAN_RAW into the kernel.
>
>> Oh, yes that's better.
>
> It's nicer, but it will not work if you build CAN_RAW into the kernel
> and CAN_DEV as a module....Let me think of the right kconfig magic to
> workaround this...
No need for it IMO.
I built my kernel with the CAN netlayer stuff into the kernel and
disabled the CAN_DEV stuff.
As you defined
static inline struct can_priv *safe_candev_priv(struct net_device *dev) {
return NULL;
}
in
include/linux/can/dev.h
this function is now inside raw.c which compiles excellent.
Building without CONFIG_CAN_DEV is not a valid use-case anyway.
It would only make sense, if someone wants to create an out-of-tree CAN
driver without netlink ...
Best regards,
Oliver
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [net-next] can: raw: fix build without CONFIG_CAN_DEV
2025-11-27 23:03 ` Oliver Hartkopp
@ 2025-11-27 23:24 ` Oliver Hartkopp
0 siblings, 0 replies; 6+ messages in thread
From: Oliver Hartkopp @ 2025-11-27 23:24 UTC (permalink / raw)
To: Marc Kleine-Budde; +Cc: linux-can, netdev, davem, kuba, kernel, Vincent Mailhol
Answering myself:
You were right (raw.c built-in, drivers as modules):
ld: net/can/raw.o: in function `raw_check_txframe':
/home/hartko/linux/net/can/raw.c:933:(.text+0xb2c): undefined reference
to `safe_candev_priv'
make[2]: *** [scripts/Makefile.vmlinux:72: vmlinux.unstripped] Error 1
make[1]: *** [/home/hartko/linux/Makefile:1242: vmlinux] Error 2
make: *** [Makefile:248: __sub-make] Error 2
Maybe its a better task for tomorrow ...
Sorry for the noise.
Best regards,
Oliver
On 28.11.25 00:03, Oliver Hartkopp wrote:
> Hello Marc,
>
> On 27.11.25 23:43, Marc Kleine-Budde wrote:
>> On 27.11.2025 23:35:48, Oliver Hartkopp wrote:
>>>> That's not sufficient. We can build the CAN_DEV as a module but compile
>>>> CAN_RAW into the kernel.
>>
>>> Oh, yes that's better.
>>
>> It's nicer, but it will not work if you build CAN_RAW into the kernel
>> and CAN_DEV as a module....Let me think of the right kconfig magic to
>> workaround this...
>
> No need for it IMO.
>
> I built my kernel with the CAN netlayer stuff into the kernel and
> disabled the CAN_DEV stuff.
>
> As you defined
>
> static inline struct can_priv *safe_candev_priv(struct net_device *dev) {
> return NULL;
> }
>
> in
>
> include/linux/can/dev.h
>
> this function is now inside raw.c which compiles excellent.
>
> Building without CONFIG_CAN_DEV is not a valid use-case anyway.
>
> It would only make sense, if someone wants to create an out-of-tree CAN
> driver without netlink ...
>
> Best regards,
> Oliver
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-11-27 23:25 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-27 21:07 [net-next] can: raw: fix build without CONFIG_CAN_DEV Oliver Hartkopp
2025-11-27 22:22 ` 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
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).