Re: [PATCH] iio: light: bh1745: fix 16-bit register accesses

From: Arnav Kapoor

Date: Tue Nov 17 2026 - 05:42:02 EST


On Tue, Nov 17, 2026 at 12:21:42PM +0200, Andy Shevchenko wrote:
> On Tue, Nov 17, 2026 at 01:12:10AM +0530, Arnav Kapoor wrote:
> > - bh1745_trigger_handler() stores the raw bytes in a u16 although the
> > scan type is IIO_CPU.
>
> I didn't get this, what's the problem here?

The handler does regmap_bulk_read(..., &value, 2) into a u16 and puts
that straight into scan.chans[], so the buffer gets the register bytes
as they come off the bus, LSB first. The channels declare
.endianness = IIO_CPU, so user space reads each sample as a native u16.
That is right on little-endian, but on big-endian every sample comes
out byte-swapped. The patch reads into an __le16 and stores
le16_to_cpu(value), so the data matches IIO_CPU on both.

I'll reword that bullet in v2 to say this directly.

> Otherwise seems legit to me.
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>

Thanks!

> And you also need to add
>
> asm/byteorder.h.

Will do in v2.

Thanks,
Arnav