Re: [PATCH v4 2/2] iio: adc: ad_sigma_delta: fix clear_pending_event for registerless devices

From: Uwe Kleine-König

Date: Fri May 22 2026 - 11:25:07 EST


Hello,

[adding Thomas to the discussion as he also participated in the old
linked discussion]

On Fri, May 22, 2026 at 02:51:43PM +0100, Jonathan Cameron wrote:
> On Thu, 21 May 2026 13:30:49 +0300
> Radu Sabau via B4 Relay <devnull+radu.sabau.analog.com@xxxxxxxxxx> wrote:
>
> > From: Radu Sabau <radu.sabau@xxxxxxxxxx>
> >
> > ad_sigma_delta_clear_pending_event() falls through to the status register
> > read path for devices with has_registers = false and no rdy_gpiod. For
> > such devices, ad_sd_read_reg() skips the address byte entirely and clocks
> > raw MISO bytes with no address phase — making it byte-for-byte identical
> > to reading conversion data. If a pending conversion result is present,
> > this partially consumes it and corrupts the data stream for the subsequent
> > ad_sd_read_reg() call in ad_sigma_delta_single_conversion().
> >
> > Furthermore, with num_resetclks = 0 on these devices, data_read_len
> > evaluates to 0. If the clocked byte has bit 7 clear, pending_event is set
> > and the code attempts memset(data + 2, 0xff, 0 - 1), overflowing to
> > SIZE_MAX and corrupting the heap.
> >
> > Fix by returning 0 immediately when neither rdy_gpiod nor has_registers
> > is set. This is safe because the IRQ is requested with IRQF_NO_AUTOEN and
> > IRQ_DISABLE_UNLAZY, which keeps the hardware IRQ line unmasked even while
> > software-disabled. Any falling edge from a completed conversion is latched
> > by the IRQ controller.
>
> David raised this on v2.
>
> This sounds suspiciously like we are in implementation defined territory.
> IIRC if an irq is disabled, whether the interrupt is latched is down
> to whether the irq controller happens to do so. There is no hard rule on this
> or way to detect whether it will or not.
>
> https://lore.kernel.org/all/io53lznz3qp3jd5rohqsjhosnmdzd6d44sdbwu5jcfrs3rz2a2@orquwgflrtyc/
> Was I think the most recent detailed thread on this.
>
> Uwe - you were driving that discussion can you sanity check what we have
> here if you have a moment? Thanks!

Without having looked at the code but skimmed through the old discussion
again, the result back then was that you won't get reliable behaviour
without rdy-gpio.

I didn't try to understand what's different fro "registerless devices",
but I doubt this implements a robust solution.

Best regards
Uwe

Attachment: signature.asc
Description: PGP signature