Re: [PATCH] iio: proximity: aw96103: fix firmware read on big-endian

From: Jonathan Cameron

Date: Sat Mar 21 2026 - 16:14:31 EST


On Mon, 16 Mar 2026 09:36:33 -0500
David Lechner <dlechner@xxxxxxxxxxxx> wrote:

> On 3/16/26 5:22 AM, Andy Shevchenko wrote:
> > On Sat, Mar 14, 2026 at 06:20:12PM -0500, David Lechner wrote:
> >> Use get_unaligned_le32() instead of casting to int * to make sure that
> >> reading a 32-bit int value from the firmware binary works correctly on
> >> big-endian architectures.
> >
> > ...
> >
> >> bin->valid_data_addr = AW96103_BIN_VALID_DATA_OFFSET;
> >> bin->valid_data_len =
> >> - *(unsigned int *)(bin->data + AW96103_BIN_DATA_LEN_OFFSET) -
> >> + get_unaligned_le32(bin->data + AW96103_BIN_DATA_LEN_OFFSET) -
> >> AW96103_BIN_DATA_REG_NUM_SIZE;
> >> memcpy(bin->chip_type, bin->data + AW96103_BIN_CHIP_TYPE_OFFSET,
> >> AW96103_BIN_CHIP_TYPE_SIZE);
> >
> > I gave you a tag, but I have a question here:
> > Hmm... memcpy() happens to work probably due to keeping LE as LE and chip_type
> > being a byte stream itself, if AW96103_BIN_CHIP_TYPE_SIZE is bigger than a
> > byte. Otherwise it may suffer from the same issue, no?
> >
>
> I checked how bin->chip_type is used and it is a string, so not affected.

I'll give this one a bit longer so Shuaijie can hopefully take a look.