Skip to content

Commit 4650ff5

Browse files
hartkoppmarckleinebudde
authored andcommitted
Revert "can: raw: instantly reject unsupported CAN frames"
This reverts commit 1a620a7 and its follow-up fixes for the introduced dependency issues. commit 1a620a7 ("can: raw: instantly reject unsupported CAN frames") commit cb2dc6d ("can: Kconfig: select CAN driver infrastructure by default") commit 6abd457 ("can: fix build dependency") commit 5a5aff6 ("can: fix build dependency") The entire problem was caused by the requirement that a new network layer feature needed to know about the protocol capabilities of the CAN devices. Instead of accessing CAN device internal data structures which caused the dependency problems a better approach has been developed which makes use of CAN specific ml_priv data which is accessible from both sides. Cc: Marc Kleine-Budde <mkl@pengutronix.de> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Vincent Mailhol <mailhol@kernel.org> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net> Link: https://patch.msgid.link/20260109144135.8495-2-socketcan@hartkopp.net Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
1 parent 3879cff commit 4650ff5

5 files changed

Lines changed: 17 additions & 58 deletions

File tree

drivers/net/can/Kconfig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22

33
menuconfig CAN_DEV
4-
bool "CAN Device Drivers"
4+
tristate "CAN Device Drivers"
55
default y
66
depends on CAN
77
help
@@ -17,7 +17,10 @@ menuconfig CAN_DEV
1717
virtual ones. If you own such devices or plan to use the virtual CAN
1818
interfaces to develop applications, say Y here.
1919

20-
if CAN_DEV && CAN
20+
To compile as a module, choose M here: the module will be called
21+
can-dev.
22+
23+
if CAN_DEV
2124

2225
config CAN_VCAN
2326
tristate "Virtual Local CAN Interface (vcan)"

drivers/net/can/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ obj-$(CONFIG_CAN_VCAN) += vcan.o
77
obj-$(CONFIG_CAN_VXCAN) += vxcan.o
88
obj-$(CONFIG_CAN_SLCAN) += slcan/
99

10-
obj-$(CONFIG_CAN_DEV) += dev/
10+
obj-y += dev/
1111
obj-y += esd/
1212
obj-y += rcar/
1313
obj-y += rockchip/

drivers/net/can/dev/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# SPDX-License-Identifier: GPL-2.0
22

3-
obj-$(CONFIG_CAN) += can-dev.o
3+
obj-$(CONFIG_CAN_DEV) += can-dev.o
4+
5+
can-dev-y += skb.o
46

5-
can-dev-$(CONFIG_CAN_DEV) += skb.o
67
can-dev-$(CONFIG_CAN_CALC_BITTIMING) += calc_bittiming.o
78
can-dev-$(CONFIG_CAN_NETLINK) += bittiming.o
89
can-dev-$(CONFIG_CAN_NETLINK) += dev.o

include/linux/can/dev.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,7 @@ struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max,
111111
void free_candev(struct net_device *dev);
112112

113113
/* a candev safe wrapper around netdev_priv */
114-
#if IS_ENABLED(CONFIG_CAN_NETLINK)
115114
struct can_priv *safe_candev_priv(struct net_device *dev);
116-
#else
117-
static inline struct can_priv *safe_candev_priv(struct net_device *dev)
118-
{
119-
return NULL;
120-
}
121-
#endif
122115

123116
int open_candev(struct net_device *dev);
124117
void close_candev(struct net_device *dev);

net/can/raw.c

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -892,58 +892,20 @@ static void raw_put_canxl_vcid(struct raw_sock *ro, struct sk_buff *skb)
892892
}
893893
}
894894

895-
static inline bool raw_dev_cc_enabled(struct net_device *dev,
896-
struct can_priv *priv)
895+
static unsigned int raw_check_txframe(struct raw_sock *ro, struct sk_buff *skb, int mtu)
897896
{
898-
/* The CANXL-only mode disables error-signalling on the CAN bus
899-
* which is needed to send CAN CC/FD frames
900-
*/
901-
if (priv)
902-
return !can_dev_in_xl_only_mode(priv);
903-
904-
/* virtual CAN interfaces always support CAN CC */
905-
return true;
906-
}
907-
908-
static inline bool raw_dev_fd_enabled(struct net_device *dev,
909-
struct can_priv *priv)
910-
{
911-
/* check FD ctrlmode on real CAN interfaces */
912-
if (priv)
913-
return (priv->ctrlmode & CAN_CTRLMODE_FD);
914-
915-
/* check MTU for virtual CAN FD interfaces */
916-
return (READ_ONCE(dev->mtu) >= CANFD_MTU);
917-
}
918-
919-
static inline bool raw_dev_xl_enabled(struct net_device *dev,
920-
struct can_priv *priv)
921-
{
922-
/* check XL ctrlmode on real CAN interfaces */
923-
if (priv)
924-
return (priv->ctrlmode & CAN_CTRLMODE_XL);
925-
926-
/* check MTU for virtual CAN XL interfaces */
927-
return can_is_canxl_dev_mtu(READ_ONCE(dev->mtu));
928-
}
929-
930-
static unsigned int raw_check_txframe(struct raw_sock *ro, struct sk_buff *skb,
931-
struct net_device *dev)
932-
{
933-
struct can_priv *priv = safe_candev_priv(dev);
934-
935-
/* Classical CAN */
936-
if (can_is_can_skb(skb) && raw_dev_cc_enabled(dev, priv))
897+
/* Classical CAN -> no checks for flags and device capabilities */
898+
if (can_is_can_skb(skb))
937899
return CAN_MTU;
938900

939-
/* CAN FD */
901+
/* CAN FD -> needs to be enabled and a CAN FD or CAN XL device */
940902
if (ro->fd_frames && can_is_canfd_skb(skb) &&
941-
raw_dev_fd_enabled(dev, priv))
903+
(mtu == CANFD_MTU || can_is_canxl_dev_mtu(mtu)))
942904
return CANFD_MTU;
943905

944-
/* CAN XL */
906+
/* CAN XL -> needs to be enabled and a CAN XL device */
945907
if (ro->xl_frames && can_is_canxl_skb(skb) &&
946-
raw_dev_xl_enabled(dev, priv))
908+
can_is_canxl_dev_mtu(mtu))
947909
return CANXL_MTU;
948910

949911
return 0;
@@ -999,7 +961,7 @@ static int raw_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
999961
err = -EINVAL;
1000962

1001963
/* check for valid CAN (CC/FD/XL) frame content */
1002-
txmtu = raw_check_txframe(ro, skb, dev);
964+
txmtu = raw_check_txframe(ro, skb, READ_ONCE(dev->mtu));
1003965
if (!txmtu)
1004966
goto free_skb;
1005967

0 commit comments

Comments
 (0)