Re: [RFC PATCH v5 3/5] can: dev: add CAN XL support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 22.07.2022 12:20:43, Vincent Mailhol wrote:
> I do not buy your argument that you can not do sizeof(struct
> canxl_frame) because of naming.
> 
> With a flexible array member, I can do:
> 
> struct canxl_frame {
>          canid_t prio;  /* 11 bit priority for arbitration (canid_t) */
>          __u8    flags; /* additional flags for CAN XL */
>          __u8    sdt;   /* SDU (service data unit) type */
>          __u16   len;   /* frame payload length in byte */
>          __u32   af;    /* acceptance field */
>          __u8    data[];
> };
> 
> void foo (int s)
> {
>          struct canxl_frame cxl_hdr = { 0 };
>          struct canxl_frame *cxl1, *cxl2;
>          size_t cxl2_data_len, cxl2_frame_len;
> 
>          /* read header */
>          assert(read(s, &cxl_hdr, sizeof(cxl_hdr)) == sizeof(cxl_hdr));
>          cxl1 = malloc(sizeof(*cxl1) + cxl_hdr.len);
>          memcpy(cxl1, &cxl_hdr, sizeof(cxl_hdr));
>          /* read remaining data */
>          assert(read(s, cxl1->data, cxl1->len) == cxl1->len);

For performance reasons you probable don't want to split the read of a
single CAN frame over 2 read() syscalls. Also the CAN_RAW doesn't
support "split"-read now, but could be extended.

Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Automotive Discussions]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [CAN Bus]

  Powered by Linux