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

From: Andy Shevchenko

Date: Tue Nov 17 2026 - 05:21:55 EST


On Tue, Nov 17, 2026 at 01:12:10AM +0530, Arnav Kapoor wrote:
> The 16-bit colour data and threshold registers are little-endian
> LSB/MSB pairs, but the driver accesses them through regmap_bulk_read()
> and regmap_bulk_write() with an int or u16 buffer and no byte-order
> conversion:
>
> - bh1745_read_raw() reads 2 bytes into an uninitialised int, so the
> upper 16 bits returned to user space are stack contents.
> - bh1745_read_thresh() reads 2 bytes straight into *val, which the IIO
> core leaves uninitialised, with the same result for the event
> threshold attributes.
> - bh1745_write_thresh() writes the first 2 bytes of an int, which are
> the upper (zero) bytes on big-endian.

> - 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?

> Use an __le16 buffer for all of them and convert with le16_to_cpu() /
> cpu_to_le16().

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

And you also need to add

asm/byteorder.h.

--
With Best Regards,
Andy Shevchenko