Re: [PATCH v3 2/3] iio: accel: bmc150: use DMA-safe buffers for regmap bulk reads
From: Andy Shevchenko
Date: Mon Aug 31 2026 - 03:00:45 EST
On Mon, Aug 31, 2026 at 01:24:50AM +0100, Jonathan Cameron wrote:
> On Thu, 27 Aug 2026 10:05:19 +0300
> Andy Shevchenko <andriy.shevchenko@xxxxxxxxx> wrote:
> > On Tue, Aug 25, 2026 at 02:21:55PM +0530, Yash Suthar wrote:
...
> > > j = 0;
> > > iio_for_each_active_channel(indio_dev, bit)
> > > - memcpy(&data->scan.channels[j++], &buffer[i * 3 + bit],
> > > + memcpy(&data->scan.channels[j++],
> > > + &data->fifo_buff[i * 3 + bit],
> > > sizeof(data->scan.channels[0]));
> >
> > While this works, I find a bit confusing usage of [j++] and [0] together.
> >
> > IIUC the below is an equivalent
> >
> > iio_for_each_active_channel(indio_dev, bit) {
> > __le16 *val = &data->scan.channels[j++];
> >
> > memcpy(val, &data->fifo_buff[i * 3 + bit], sizeof(val));
> > }
>
> This bit I fully agree with. Much more readable.
> >
> > and if go further we may use asm/byteorder.h macros instead of plain memcpy().
> >
> Here I'm lost. We are just moving little endian values around.
>
> For that matter if it is a single value, why can't see just assign it?
>
> iio_for_each_active_channel(indio_dev, bit)
> data->scan.channels[j++] = data->fifo_buf[i * 3 + bit];
It depends on the alignment. I haven't checked the assignee and the source
for that. That's why I mentioned byteorder.h (and implying also unaligned.h)
for the cases like put_unaligned_le16(le16_to_cpup(val)). If both sides are
aligned, then yours suggestion will work.
--
With Best Regards,
Andy Shevchenko