Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

can: introduce CAN_REQUIRED_SIZE macro

The size of this structure will be increased with J1939 support. To stay
binary compatible, the CAN_REQUIRED_SIZE macro is introduced for
existing CAN protocols.

Signed-off-by: Kurt Van Dijck <dev.kurt@vandijck-laurijssen.be>
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

authored by

Kurt Van Dijck and committed by
Marc Kleine-Budde
9868b5d4 4f746fb4

+12 -4
+8
include/linux/can/core.h
··· 41 41 struct proto *prot; 42 42 }; 43 43 44 + /* required_size 45 + * macro to find the minimum size of a struct 46 + * that includes a requested member 47 + */ 48 + #define CAN_REQUIRED_SIZE(struct_type, member) \ 49 + (offsetof(typeof(struct_type), member) + \ 50 + sizeof(((typeof(struct_type) *)(NULL))->member)) 51 + 44 52 /* function prototypes for the CAN networklayer core (af_can.c) */ 45 53 46 54 extern int can_proto_register(const struct can_proto *cp);
+2 -2
net/can/bcm.c
··· 1294 1294 /* no bound device as default => check msg_name */ 1295 1295 DECLARE_SOCKADDR(struct sockaddr_can *, addr, msg->msg_name); 1296 1296 1297 - if (msg->msg_namelen < sizeof(*addr)) 1297 + if (msg->msg_namelen < CAN_REQUIRED_SIZE(*addr, can_ifindex)) 1298 1298 return -EINVAL; 1299 1299 1300 1300 if (addr->can_family != AF_CAN) ··· 1536 1536 struct net *net = sock_net(sk); 1537 1537 int ret = 0; 1538 1538 1539 - if (len < sizeof(*addr)) 1539 + if (len < CAN_REQUIRED_SIZE(*addr, can_ifindex)) 1540 1540 return -EINVAL; 1541 1541 1542 1542 lock_sock(sk);
+2 -2
net/can/raw.c
··· 396 396 int err = 0; 397 397 int notify_enetdown = 0; 398 398 399 - if (len < sizeof(*addr)) 399 + if (len < CAN_REQUIRED_SIZE(*addr, can_ifindex)) 400 400 return -EINVAL; 401 401 if (addr->can_family != AF_CAN) 402 402 return -EINVAL; ··· 733 733 if (msg->msg_name) { 734 734 DECLARE_SOCKADDR(struct sockaddr_can *, addr, msg->msg_name); 735 735 736 - if (msg->msg_namelen < sizeof(*addr)) 736 + if (msg->msg_namelen < CAN_REQUIRED_SIZE(*addr, can_ifindex)) 737 737 return -EINVAL; 738 738 739 739 if (addr->can_family != AF_CAN)