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

From: Andy Shevchenko

Date: Tue Nov 17 2026 - 05:52:35 EST


On Tue, Nov 17, 2026 at 04:11:52PM +0530, Arnav Kapoor wrote:
> 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.

Yes, please do.

--
With Best Regards,
Andy Shevchenko