Skip to content

Commit

Permalink
can: introduce CAN_REQUIRED_SIZE macro
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Oleksij Rempel <[email protected]>
Acked-by: Oliver Hartkopp <[email protected]>
Signed-off-by: Marc Kleine-Budde <[email protected]>
  • Loading branch information
kurt-vd authored and marckleinebudde committed Sep 4, 2019
1 parent 4f746fb commit 9868b5d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
8 changes: 8 additions & 0 deletions include/linux/can/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ struct can_proto {
struct proto *prot;
};

/* required_size
* macro to find the minimum size of a struct
* that includes a requested member
*/
#define CAN_REQUIRED_SIZE(struct_type, member) \
(offsetof(typeof(struct_type), member) + \
sizeof(((typeof(struct_type) *)(NULL))->member))

/* function prototypes for the CAN networklayer core (af_can.c) */

extern int can_proto_register(const struct can_proto *cp);
Expand Down
4 changes: 2 additions & 2 deletions net/can/bcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ static int bcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
/* no bound device as default => check msg_name */
DECLARE_SOCKADDR(struct sockaddr_can *, addr, msg->msg_name);

if (msg->msg_namelen < sizeof(*addr))
if (msg->msg_namelen < CAN_REQUIRED_SIZE(*addr, can_ifindex))
return -EINVAL;

if (addr->can_family != AF_CAN)
Expand Down Expand Up @@ -1536,7 +1536,7 @@ static int bcm_connect(struct socket *sock, struct sockaddr *uaddr, int len,
struct net *net = sock_net(sk);
int ret = 0;

if (len < sizeof(*addr))
if (len < CAN_REQUIRED_SIZE(*addr, can_ifindex))
return -EINVAL;

lock_sock(sk);
Expand Down
4 changes: 2 additions & 2 deletions net/can/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ static int raw_bind(struct socket *sock, struct sockaddr *uaddr, int len)
int err = 0;
int notify_enetdown = 0;

if (len < sizeof(*addr))
if (len < CAN_REQUIRED_SIZE(*addr, can_ifindex))
return -EINVAL;
if (addr->can_family != AF_CAN)
return -EINVAL;
Expand Down Expand Up @@ -733,7 +733,7 @@ static int raw_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
if (msg->msg_name) {
DECLARE_SOCKADDR(struct sockaddr_can *, addr, msg->msg_name);

if (msg->msg_namelen < sizeof(*addr))
if (msg->msg_namelen < CAN_REQUIRED_SIZE(*addr, can_ifindex))
return -EINVAL;

if (addr->can_family != AF_CAN)
Expand Down

0 comments on commit 9868b5d

Please sign in to comment.