Re: [PATCH v1 1/2] spi: Add spi_bpw_to_bytes() helper and use it

From: Andy Shevchenko
Date: Wed Apr 16 2025 - 11:14:18 EST


On Wed, Apr 16, 2025 at 09:56:12AM -0500, David Lechner wrote:
> On 4/16/25 1:16 AM, Andy Shevchenko wrote:

...

> > +/**
> > + * spi_bpw_to_bytes - Covert bits per word to bytes
> > + * @bpw: Bits per word
> > + *
> > + * This function converts the given @bpw to bytes. The result is always
> > + * power-of-two (e.g. for 37 bits it returns 8 bytes) or 0 for 0 input.
>
> The SPI subsystem currently only supports bpw up to 32, so perhaps not
> the best choice of value for the example. I would go with 20 bits getting
> rounded up to 4 bytes to match the existing docs for @bits_per_word.

Okay, I think I come up with a few examples, so it will show that it's not
4-byte multiple or so.

> > + * Returns:
> > + * Bytes for the given @bpw.
> > + */
> > +static inline u32 spi_bpw_to_bytes(u32 bpw)
> > +{
> > + return roundup_pow_of_two(BITS_TO_BYTES(bpw));

> Do we need to #include <linux/log2.h> for roundup_pow_of_two()?

Right now I prefer not to touch that (it is implicitly included); the headers
needs to have a bigger cleanup and my first attempt had miserably failed.

> > +}

--
With Best Regards,
Andy Shevchenko