[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75VfuCkohVLUJKgcMrgad-fRk4aKx_Ki0gRxxhJP3qgvS1g@mail.gmail.com>
Date: Wed, 16 Apr 2025 09:01:02 +0300
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: David Lechner <dlechner@...libre.com>
Cc: Marcelo Schmitt <marcelo.schmitt@...log.com>, linux-iio@...r.kernel.org,
linux-kernel@...r.kernel.org, jic23@...nel.org, lars@...afoo.de,
Michael.Hennerich@...log.com, nuno.sa@...log.com, andy@...nel.org,
marcelo.schmitt1@...il.com
Subject: Re: [PATCH] iio: adc: ad4000: Avoid potential double data word read
On Wed, Apr 16, 2025 at 8:59 AM Andy Shevchenko
<andy.shevchenko@...il.com> wrote:
> On Wed, Apr 16, 2025 at 12:22 AM David Lechner <dlechner@...libre.com> wrote:
> > On 4/15/25 1:02 PM, Andy Shevchenko wrote:
> > > On Tue, Apr 15, 2025 at 3:21 PM Marcelo Schmitt
> > > <marcelo.schmitt@...log.com> wrote:
...
> > >> xfers[1].rx_buf = &st->scan.data;
> > >> - xfers[1].len = BITS_TO_BYTES(chan->scan_type.storagebits);
> > >> + xfers[1].len = chan->scan_type.realbits > 16 ? 4 : 2;
> > >
> > > But wouldn't be logical to have
> > >
> > > xfers[1].len = BITS_TO_BYTES(chan->scan_type.realbits);
> > >
> > > ?
> >
> > No, SPI expects 1, 2 or 4 bytes, never 3. If realbits is 18, we
> > need len = 4.
> >
> > It would have to be:
> >
> > xfers[1].len = roundup_pow_of_two(BITS_TO_BYTES(chan->scan_type.realbits));
> >
> > But that gets too long for 1 line
>
> Actually there are a handful of drivers including SPI core that need
> that helper already, I would prefer to have a helper defined in spi.h.
>
> , so I prefer what Marcelo wrote.
> >
> > Maybe an idea for another day:
> >
> > #define SPI_LEN_FOR_BITS(bits) roundup_pow_of_two(BITS_TO_BYTES(bits))
>
> Right, but as static inline to have stricter types.
>
> > There are a couple of places in spi/ that could use this and several
> > iio drivers.
Or even wider, in bitops.h / bit*.h somewhere. Let me craft a patch.
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists