[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMuHMdWNNu+gwHdhfaShLyXHqxD=esp4CXpWiHJCqrCGho0z3g@mail.gmail.com>
Date: Fri, 29 Aug 2025 11:47:44 +0200
From: Geert Uytterhoeven <geert@...ux-m68k.org>
To: David Lechner <dlechner@...libre.com>
Cc: Jonathan Cameron <jic23@...nel.org>, Nuno Sá <nuno.sa@...log.com>,
Andy Shevchenko <andy@...nel.org>, Mathieu Othacehe <othacehe@....org>, linux-iio@...r.kernel.org,
linux-kernel@...r.kernel.org, Jonathan Cameron <Jonathan.Cameron@...wei.com>
Subject: Re: [PATCH v2] iio: proximity: isl29501: fix buffered read on
big-endian systems
Hi David,
On Tue, 22 Jul 2025 at 22:55, David Lechner <dlechner@...libre.com> wrote:
> Fix passing a u32 value as a u16 buffer scan item. This works on little-
> endian systems, but not on big-endian systems.
>
> A new local variable is introduced for getting the register value and
> the array is changed to a struct to make the data layout more explicit
> rather than just changing the type and having to recalculate the proper
> length needed for the timestamp.
>
> Fixes: 1c28799257bc ("iio: light: isl29501: Add support for the ISL29501 ToF sensor.")
> Signed-off-by: David Lechner <dlechner@...libre.com>
Thanks for your patch, which is now commit de18e978d0cda23e ("iio:
proximity: isl29501: fix buffered read on big-endian systems")
in v6.17-rc3.
> --- a/drivers/iio/proximity/isl29501.c
> +++ b/drivers/iio/proximity/isl29501.c
> @@ -938,12 +938,18 @@ static irqreturn_t isl29501_trigger_handler(int irq, void *p)
> struct iio_dev *indio_dev = pf->indio_dev;
> struct isl29501_private *isl29501 = iio_priv(indio_dev);
> const unsigned long *active_mask = indio_dev->active_scan_mask;
> - u32 buffer[4] __aligned(8) = {}; /* 1x16-bit + naturally aligned ts */
> -
> - if (test_bit(ISL29501_DISTANCE_SCAN_INDEX, active_mask))
> - isl29501_register_read(isl29501, REG_DISTANCE, buffer);
> + u32 value;
> + struct {
> + u16 data;
> + aligned_s64 ts;
> + } scan = { };
This still looks rather obfuse to me: you rely on the implicit
presence of a 6-byte hole between data and ts, and on the implicit
64-bit alignment of data.
What about making this explicit?
struct {
u16 data;
u16 unused[3];
s64 ts;
} __aligned(8) scan = { };
> +
> + if (test_bit(ISL29501_DISTANCE_SCAN_INDEX, active_mask)) {
> + isl29501_register_read(isl29501, REG_DISTANCE, &value);
> + scan.data = value;
> + }
>
> - iio_push_to_buffers_with_timestamp(indio_dev, buffer, pf->timestamp);
> + iio_push_to_buffers_with_timestamp(indio_dev, &scan, pf->timestamp);
> iio_trigger_notify_done(indio_dev->trig);
>
> return IRQ_HANDLED;
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@...ux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Powered by blists - more mailing lists