Re: [PATCH 2/2] can: esd_usb: Add support for esd CAN-USB/3

From: Marc Kleine-Budde
Date: Tue May 09 2023 - 03:06:20 EST


On 09.05.2023 10:28:13, Vincent MAILHOL wrote:
> > > And because hdr.len is initially 3, hdr.len becomes 5. Right? Shouldn't it be 8?
> >
> > It might be a little confusing, but I think it's fine.
> > hdr.len is given in units of longwords (4 bytes each)! Therefore we
> > have 12 bytes (the initial 3 longwords) for struct tx_msg before
> > tx_msg.data[].
> > Than (8 + 3)/4=2 gives us 2 additional longwords for the 8 data bytes.
> > So that 3+2=5 (equal to 20 bytes) should be ok.

I think the term longword is more commonly used in non-Unix operating
systems :)

> OK. So you want to round up the length to the next sizeof(long) multiple, right?
>
> First, sizeof(long) being platform specific, you need to declare a
> macro to make your intent explicit.
>
> /* Size of a long int on esd devices */
> #define USB_ESD_SIZEOF_LONG 4
>
> Please test, but for what I understand, below line is an equivalent
> and a more readable way to achieve your goal:
>
> msg->hdr.len = DIV_ROUND_UP(cf->len, USB_ESD_SIZEOF_LONG);

use "sizeof(u32)"

> Also, add documentation to your structure to explain that hdr.len
> represents the length in long, not in bytes.

...lengths in multiple of u32.

Marc

--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung Nürnberg | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |

Attachment: signature.asc
Description: PGP signature