mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] iio: proximity: aw96103: fix firmware read on big-endian
@ 2026-03-14 23:20 David Lechner
  2026-03-16 10:16 ` Andy Shevchenko
  2026-03-16 10:22 ` Andy Shevchenko
  0 siblings, 2 replies; 5+ messages in thread
From: David Lechner @ 2026-03-14 23:20 UTC (permalink / raw)
  To: Jonathan Cameron, Nuno Sá, Andy Shevchenko, shuaijie wang
  Cc: Jonathan Cameron, linux-iio, linux-kernel, David Lechner

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.

Fixes: 07b241262dca ("iio: proximity: aw96103: Add support for aw96103/aw96105 proximity sensor")
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
 drivers/iio/proximity/aw96103.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/proximity/aw96103.c b/drivers/iio/proximity/aw96103.c
index 3472a2c36e44..8263411c06df 100644
--- a/drivers/iio/proximity/aw96103.c
+++ b/drivers/iio/proximity/aw96103.c
@@ -233,7 +233,7 @@ static void aw96103_parsing_bin_file(struct aw_bin *bin)
 {
 	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);

---
base-commit: ff0843ceb1fb11a6b73e0e77b932ef7967aecd4b
change-id: 20260314-iio-proximity-aw96103-fix-firmware-read-c9378ce60830

Best regards,
--  
David Lechner <dlechner@baylibre.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] iio: proximity: aw96103: fix firmware read on big-endian
  2026-03-14 23:20 [PATCH] iio: proximity: aw96103: fix firmware read on big-endian David Lechner
@ 2026-03-16 10:16 ` Andy Shevchenko
  2026-03-16 10:22 ` Andy Shevchenko
  1 sibling, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2026-03-16 10:16 UTC (permalink / raw)
  To: David Lechner
  Cc: Jonathan Cameron, Nuno Sá,
	Andy Shevchenko, shuaijie wang, Jonathan Cameron, linux-iio,
	linux-kernel

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.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] iio: proximity: aw96103: fix firmware read on big-endian
  2026-03-14 23:20 [PATCH] iio: proximity: aw96103: fix firmware read on big-endian David Lechner
  2026-03-16 10:16 ` Andy Shevchenko
@ 2026-03-16 10:22 ` Andy Shevchenko
  2026-03-16 14:36   ` David Lechner
  1 sibling, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2026-03-16 10:22 UTC (permalink / raw)
  To: David Lechner
  Cc: Jonathan Cameron, Nuno Sá,
	Andy Shevchenko, shuaijie wang, Jonathan Cameron, linux-iio,
	linux-kernel

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?

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] iio: proximity: aw96103: fix firmware read on big-endian
  2026-03-16 10:22 ` Andy Shevchenko
@ 2026-03-16 14:36   ` David Lechner
  2026-03-21 20:14     ` Jonathan Cameron
  0 siblings, 1 reply; 5+ messages in thread
From: David Lechner @ 2026-03-16 14:36 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Jonathan Cameron, Nuno Sá,
	Andy Shevchenko, shuaijie wang, Jonathan Cameron, linux-iio,
	linux-kernel

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. 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] iio: proximity: aw96103: fix firmware read on big-endian
  2026-03-16 14:36   ` David Lechner
@ 2026-03-21 20:14     ` Jonathan Cameron
  0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2026-03-21 20:14 UTC (permalink / raw)
  To: David Lechner
  Cc: Andy Shevchenko, Nuno Sá,
	Andy Shevchenko, shuaijie wang, Jonathan Cameron, linux-iio,
	linux-kernel

On Mon, 16 Mar 2026 09:36:33 -0500
David Lechner <dlechner@baylibre.com> 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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-03-21 20:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-14 23:20 [PATCH] iio: proximity: aw96103: fix firmware read on big-endian David Lechner
2026-03-16 10:16 ` Andy Shevchenko
2026-03-16 10:22 ` Andy Shevchenko
2026-03-16 14:36   ` David Lechner
2026-03-21 20:14     ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®