Re: [PATCH v6 1/3] hwmon: (ads7871) Fix endianness bug in 16-bit register reads

Guenter Roeck
2026-05-02T18:18:06Z

On Sat, May 02, 2026 at 07:38:42AM +0530, Tabrez Ahmed wrote:
> The ads7871_read_reg16() function relies on spi_w8r16() to read the
> 16-bit sensor output. The ADS7871 device transmits the Least Significant
> Byte (LSB) first.
>
> On Little-Endian architectures, spi_w8r16() correctly reconstructs the
> 16-bit value. However, on Big-Endian architectures, the byte swapping
> causes the first received byte (LSB) to be placed in the most significant
> byte of the u16, resulting in corrupted voltage readings.
>
> To fix this, cast the integer result of spi_w8r16() to a restricted
> __le16 type and convert it to the host CPU's native byte order using
> le16_to_cpu(). Negative error codes returned by the SPI core are caught
> and returned prior to the conversion to avoid mangling the error status.
>
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Closes: https://sashiko.dev/#/patchset/20260418034601.90226-1-tabreztalks@gmail.com
> Suggested-by: David Laight <david.laight.linux@gmail.com>
> Signed-off-by: Tabrez Ahmed <tabreztalks@gmail.com>

Sorry for the confusion - this is the one I applied.

Thanks,
Guenter