Re: [PATCH 08/10] spi: rzv2m-csi: Improve data types and alignment

From: Geert Uytterhoeven
Date: Mon Jul 17 2023 - 05:45:28 EST


Hi Fabrizio,

Thanks for your patch!

On Sat, Jul 15, 2023 at 3:04 AM Fabrizio Castro
<fabrizio.castro.jz@xxxxxxxxxxx> wrote:
> "unsigned int" is more appropriate than "int" for the members
> of "struct rzv2m_csi_priv".

Agreed.

> Also, members "bytes_per_word" and "errors" introduce gaps
> in the structure.

While enlarging the types does get rid of the gaps, that was not the
intent of my comment ;-)
You can reorder fields to avoid gaps, and reduce the size of the structure.

> Adjust "struct rzv2m_csi_priv" and its members usage accordingly.
> While at it, remove the unnecessary casting of "data" to
> "struct rzv2m_csi_priv*" in function "rzv2m_csi_irq_handler".
>
> Signed-off-by: Fabrizio Castro <fabrizio.castro.jz@xxxxxxxxxxx>

> --- a/drivers/spi/spi-rzv2m-csi.c
> +++ b/drivers/spi/spi-rzv2m-csi.c

> @@ -88,14 +88,14 @@ struct rzv2m_csi_priv {
> struct spi_controller *controller;
> const void *txbuf;
> void *rxbuf;
> - int buffer_len;
> - int bytes_sent;
> - int bytes_received;
> - int bytes_to_transfer;
> - int words_to_transfer;
> - unsigned char bytes_per_word;
> + unsigned int buffer_len;
> + unsigned int bytes_sent;
> + unsigned int bytes_received;
> + unsigned int bytes_to_transfer;
> + unsigned int words_to_transfer;
> + unsigned int bytes_per_word;

bytes_per_word is calculated from spi_transfer.bits_per_word,
so u8 was fine.

> wait_queue_head_t wait;
> - u8 errors;
> + u32 errors;

u8 was sufficiently large to hold all possible values.

> u32 status;
> };
>

Anyway, the code should work fine, so
Reviewed-by: Geert Uytterhoeven <geert+renesas@xxxxxxxxx>

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds