Re: [patch 2/7] CAN: Add PF_CAN core module

Arnaldo Carvalho de Melo
2007-05-16T16:35:47Z

On 5/16/07, Urs Thuermann <urs@isnogud.escape.de> wrote:
> This patch adds the CAN core functionality but no protocols or drivers.
> No protocol implementations are included here. They come as separate
> patches. Protocol numbers are already in include/linux/can.h.
>
> Signed-Off-By: Oliver Hartkopp <oliver.hartkopp@volkswagen.de>
> Signed-Off-By: Urs Thuermann <urs.thuermann@volkswagen.de>

<SNIP>

> +
> +/**
> + * struct sockaddr_can - the sockaddr structure for CAN sockets
> + * @can_family: address family number AF_CAN.
> + * @can_ifindex: CAN network interface index.
> + * @can_addr: transport protocol specific address, mostly CAN IDs.
> + */
> +struct sockaddr_can {
> + sa_family_t can_family;
> + int can_ifindex;
> + union {
> + struct { canid_t rx_id, tx_id; } tp16;
> + struct { canid_t rx_id, tx_id; } tp20;
> + struct { canid_t rx_id, tx_id; } mcnet;
> + struct { canid_t rx_id, tx_id; } isotp;
> + struct { int lcu, type; } bap;
> + } can_addr;
> +};

Can can_ifindex be turned into a unsigned short? That way we would
have it nicely packed, avoiding this hole:

[acme@filo examples]$ pahole can
/* <1c2> /home/acme/git/pahole/examples/can.c:5 */
struct sockaddr_can {
sa_family_t can_family; /* 0 2 */

/* XXX 2 bytes hole, try to pack */

int can_ifindex; /* 4 4 */
union {
struct {
canid_t rx_id; /* 8 4 */
canid_t tx_id; /* 12 4 */
} tp16; /* 8 */
struct {
canid_t rx_id; /* 8 4 */
canid_t tx_id; /* 12 4 */
} tp20; /* 8 */
struct {
canid_t rx_id; /* 8 4 */
canid_t tx_id; /* 12 4 */
} mcnet; /* 8 */
struct {
canid_t rx_id; /* 8 4 */
canid_t tx_id; /* 12 4 */
} isotp; /* 8 */
struct {
int lcu; /* 8 4 */
int type; /* 12 4 */
} bap; /* 8 */
} can_addr; /* 8 8 */
}; /* size: 16, cachelines: 1 */
/* sum members: 14, holes: 1, sum holes: 2 */
/* last cacheline: 16 bytes */
/* definitions: 1 */

- Arnaldo