iio: adc: ad_sigma_delta: fix CS held asserted after single conversion
Subsystems (2)
PATCH v2 1/1 iio: adc: ad_sigma_delta: fix CS held asserted after single conversion
Commit 132d44dc6966 ("iio: adc: ad_sigma_delta: Check for previous ready signals") introduced a new out_unlock: label for an early-exit path and moved sigma_delta->keep_cs_asserted = false there. Unfortunately it left both ad_sigma_delta_set_mode(AD_SD_MODE_IDLE) and ad_sigma_delta_disable_one() in the out: block above that label, so both SPI writes are issued while keep_cs_asserted is still true. keep_cs_asserted feeds directly into the cs_change field of the spi_transfer, so the final write to the device carries cs_change=1. The SPI framework only calls spi_set_cs() to deassert CS as part of message teardown when cs_change is not set on the last transfer; with cs_change=1, that teardown is skipped and CS stays physically asserted. No further transfer to the device is made, so the driver never deasserts CS. The framework provides no automatic CS deassert on bus unlock or when switching to another device, so CS remains stuck low until the next SPI operation to that same device.
On a shared SPI bus this is problematic: with CS stuck low the ADC remains selected and subsequent SPI traffic intended for another device is interpreted as commands by the ADC. Devices like the AD7124 that multiplex /RDY onto the MISO line will start spurious conversions and pull MISO low, corrupting reads from the other device and causing a deadlock.
Fix both calls by moving them into the out_unlock: block, after keep_cs_asserted is cleared, mirroring the existing correct pattern in ad_sd_calibrate(). With keep_cs_asserted false, both set_mode(IDLE) and disable_one() execute with cs_change=0, so the SPI framework deasserts CS as part of normal message teardown. For devices that do not implement the optional disable_one callback, set_mode(IDLE) issues the last SPI transfer and CS is properly released in all cases.
Also fix a pre-existing state leak in ad_sd_buffer_postenable(): theerr_unlock: error path called spi_bus_unlock() without first resetting bus_locked and keep_cs_asserted to false. Subsequent SPI calls would observe bus_locked == true and invoke spi_sync_locked() on a controller that is no longer locked, potentially allowing concurrent bus access.
---
Changes in v2:
- Move set_mode(AD_SD_MODE_IDLE) into out_unlock: as well, not only disable_one(); v1 left set_mode() above the label where
keep_cs_asserted is still true, so devices without the optional
disable_one callback still had CS stuck after that transfer.
- Fix pre-existing state leak in ad_sd_buffer_postenable() err_unlock:
reset bus_locked and keep_cs_asserted before spi_bus_unlock() to
prevent spi_sync_locked() being called on an unlocked controller.
- Link to v1: https://lore.kernel.org/r/[email protected]
--- drivers/iio/adc/ad_sigma_delta.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/iio/adc/ad_sigma_delta.c +4 -3
@@ -441,11 +441,10 @@ int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev, out:ad_sd_disable_irq (sigma_delta); -ad_sigma_delta_set_mode (sigma_delta,AD_SD_MODE_IDLE ); -ad_sigma_delta_disable_one (sigma_delta, chan->address); - out_unlock: sigma_delta->keep_cs_asserted = false; +ad_sigma_delta_set_mode (sigma_delta,AD_SD_MODE_IDLE ); +ad_sigma_delta_disable_one (sigma_delta, chan->address); sigma_delta->bus_locked = false;spi_bus_unlock (sigma_delta->spi->controller); out_release:
@@ -578,6 +577,8 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)return 0 ; err_unlock: + sigma_delta->keep_cs_asserted = false; + sigma_delta->bus_locked = false;spi_bus_unlock (sigma_delta->spi->controller);spi_unoptimize_message (&sigma_delta->sample_msg);
---
base-commit: 3b3bea6d4b9c162f9e555905d96b8c1da67ecd5b
change-id: 20260428-ad_sigma_delta-fix-bb65d56ccbb0
Best regards,
Signature · 1 line
Radu Sabau <[email protected]>
Quoted 39 lines · On Thu, 07 May 2026 17:00:38 +0300 Radu Sabau via B4 Relay…
From: Radu Sabau <[email protected]>
Commit
132d44dc6966("iio: adc:ad_sigma_delta: Check for previous ready signals") introduced a newout_unlock: label for an early-exit path and movedsigma_delta->keep_cs_asserted= false there. Unfortunately it left bothad_sigma_delta_set_mode(AD_SD_MODE_IDLE)andad_sigma_delta_disable_one()in the out: block above that label, so both SPI writes are issued whilekeep_cs_assertedis still true.keep_cs_assertedfeeds directly into thecs_changefield of thespi_transfer, so the final write to the device carries cs_change=1. The SPI framework only callsspi_set_cs()to deassert CS as part of message teardown whencs_changeis not set on the last transfer; with cs_change=1, that teardown is skipped and CS stays physically asserted. No further transfer to the device is made, so the driver never deasserts CS. The framework provides no automatic CS deassert on bus unlock or when switching to another device, so CS remains stuck low until the next SPI operation to that same device.On a shared SPI bus this is problematic: with CS stuck low the ADC remains selected and subsequent SPI traffic intended for another device is interpreted as commands by the ADC. Devices like the AD7124 that multiplex /RDY onto the MISO line will start spurious conversions and pull MISO low, corrupting reads from the other device and causing a deadlock.
Fix both calls by moving them into the
out_unlock: block, afterkeep_cs_assertedis cleared, mirroring the existing correct pattern inad_sd_calibrate(). Withkeep_cs_assertedfalse, bothset_mode(IDLE)anddisable_one()execute with cs_change=0, so the SPI framework deasserts CS as part of normal message teardown. For devices that do not implement the optionaldisable_onecallback,set_mode(IDLE)issues the last SPI transfer and CS is properly released in all cases.Also fix a pre-existing state leak in
ad_sd_buffer_postenable(): theerr_unlock: error path calledspi_bus_unlock()without first resettingbus_lockedandkeep_cs_assertedto false. Subsequent SPI calls would observebus_locked== true and invokespi_sync_locked()on a controller that is no longer locked, potentially allowing concurrent bus access.
Quoted 3 lines
Fixes 132d44dc6966 ("iio: adc: ad_sigma_delta: Check for previous ready signals")Acked-by Uwe Kleine-König <[email protected]>Signed-off-by Radu Sabau <[email protected]>
Applied to the fixes-togreg branch of iio.git
Depending on when I do a pull request (maybe later today) I might not include this one as it won't have had build bot exposure by then. It'll go in the next pull if that happens.
Thanks
Jonathan
Quoted 47 lines
---
Changes in v2:
- Moveset_mode(AD_SD_MODE_IDLE)intoout_unlock: as well, not onlydisable_one(); v1 leftset_mode()above the label where
keep_cs_assertedis still true, so devices without the optional
disable_onecallback still had CS stuck after that transfer.
- Fix pre-existing state leak inad_sd_buffer_postenable()err_unlock:
resetbus_lockedandkeep_cs_assertedbeforespi_bus_unlock()to
preventspi_sync_locked()being called on an unlocked controller.
- Link to v1: https://lore.kernel.org/r/[email protected]--- drivers/iio/adc/ad_sigma_delta.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/iio/adc/ad_sigma_delta.c +4
-4@@ -441,11 +441,10 @@ int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev, out:ad_sd_disable_irq (sigma_delta); -ad_sigma_delta_set_mode (sigma_delta,AD_SD_MODE_IDLE ); -ad_sigma_delta_disable_one (sigma_delta, chan->address); - out_unlock: sigma_delta->keep_cs_asserted = false; +ad_sigma_delta_set_mode (sigma_delta,AD_SD_MODE_IDLE ); +ad_sigma_delta_disable_one (sigma_delta, chan->address); sigma_delta->bus_locked = false;spi_bus_unlock (sigma_delta->spi->controller); out_release:@@ -578,6 +577,8 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)return 0 ; err_unlock: + sigma_delta->keep_cs_asserted = false; + sigma_delta->bus_locked = false;spi_bus_unlock (sigma_delta->spi->controller);spi_unoptimize_message (&sigma_delta->sample_msg); ---base-commit:
3b3bea6d4b9c162f9e555905d96b8c1da67ecd5b
change-id: 20260428-ad_sigma_delta-fix-bb65d56ccbb0Best regards,
Jonathan Cameron
maintainerQuoted 39 lines · On Thu, 07 May 2026 17:00:38 +0300 Radu Sabau via B4 Relay…
From: Radu Sabau <[email protected]>
Commit
132d44dc6966("iio: adc:ad_sigma_delta: Check for previous ready signals") introduced a newout_unlock: label for an early-exit path and movedsigma_delta->keep_cs_asserted= false there. Unfortunately it left bothad_sigma_delta_set_mode(AD_SD_MODE_IDLE)andad_sigma_delta_disable_one()in the out: block above that label, so both SPI writes are issued whilekeep_cs_assertedis still true.keep_cs_assertedfeeds directly into thecs_changefield of thespi_transfer, so the final write to the device carries cs_change=1. The SPI framework only callsspi_set_cs()to deassert CS as part of message teardown whencs_changeis not set on the last transfer; with cs_change=1, that teardown is skipped and CS stays physically asserted. No further transfer to the device is made, so the driver never deasserts CS. The framework provides no automatic CS deassert on bus unlock or when switching to another device, so CS remains stuck low until the next SPI operation to that same device.On a shared SPI bus this is problematic: with CS stuck low the ADC remains selected and subsequent SPI traffic intended for another device is interpreted as commands by the ADC. Devices like the AD7124 that multiplex /RDY onto the MISO line will start spurious conversions and pull MISO low, corrupting reads from the other device and causing a deadlock.
Fix both calls by moving them into the
out_unlock: block, afterkeep_cs_assertedis cleared, mirroring the existing correct pattern inad_sd_calibrate(). Withkeep_cs_assertedfalse, bothset_mode(IDLE)anddisable_one()execute with cs_change=0, so the SPI framework deasserts CS as part of normal message teardown. For devices that do not implement the optionaldisable_onecallback,set_mode(IDLE)issues the last SPI transfer and CS is properly released in all cases.Also fix a pre-existing state leak in
ad_sd_buffer_postenable(): theerr_unlock: error path calledspi_bus_unlock()without first resettingbus_lockedandkeep_cs_assertedto false. Subsequent SPI calls would observebus_locked== true and invokespi_sync_locked()on a controller that is no longer locked, potentially allowing concurrent bus access.
Quoted 3 lines
Fixes 132d44dc6966 ("iio: adc: ad_sigma_delta: Check for previous ready signals")Acked-by Uwe Kleine-König <[email protected]>Signed-off-by Radu Sabau <[email protected]>
Actually - dropped again. I forgot to check Sashiko.
(Note please do this yourself in future and reply to the patch if changes are needed). It raises some concerns about devices that don't provide the callbacks and hence won't ever use that keep_cs_asserted = false callback.
I'm struggling a bit on how the max11205 works at all as there seems to be a status register read on a device which claims to have no registers. ad_sigma_delta_clear_pending_event() as the binding suggests this device doesn't have a drdy_gpio
Anyhow, please take a look at the feedback and if it's wrong please provide an explanation of why in this thread.
Thanks
Jonathan
Quoted 47 lines
---
Changes in v2:
- Moveset_mode(AD_SD_MODE_IDLE)intoout_unlock: as well, not onlydisable_one(); v1 leftset_mode()above the label where
keep_cs_assertedis still true, so devices without the optional
disable_onecallback still had CS stuck after that transfer.
- Fix pre-existing state leak inad_sd_buffer_postenable()err_unlock:
resetbus_lockedandkeep_cs_assertedbeforespi_bus_unlock()to
preventspi_sync_locked()being called on an unlocked controller.
- Link to v1: https://lore.kernel.org/r/[email protected]--- drivers/iio/adc/ad_sigma_delta.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/iio/adc/ad_sigma_delta.c +4
-4@@ -441,11 +441,10 @@ int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev, out:ad_sd_disable_irq (sigma_delta); -ad_sigma_delta_set_mode (sigma_delta,AD_SD_MODE_IDLE ); -ad_sigma_delta_disable_one (sigma_delta, chan->address); - out_unlock: sigma_delta->keep_cs_asserted = false; +ad_sigma_delta_set_mode (sigma_delta,AD_SD_MODE_IDLE ); +ad_sigma_delta_disable_one (sigma_delta, chan->address); sigma_delta->bus_locked = false;spi_bus_unlock (sigma_delta->spi->controller); out_release:@@ -578,6 +577,8 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)return 0 ; err_unlock: + sigma_delta->keep_cs_asserted = false; + sigma_delta->bus_locked = false;spi_bus_unlock (sigma_delta->spi->controller);spi_unoptimize_message (&sigma_delta->sample_msg); ---base-commit:
3b3bea6d4b9c162f9e555905d96b8c1da67ecd5b
change-id: 20260428-ad_sigma_delta-fix-bb65d56ccbb0Best regards,
Quoted 3 lines
-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Tuesday, May 12, 2026 2:13 PM
...
Quoted 10 lines
Quoted 1 line
Fixes 132d44dc6966 ("iio: adc: ad_sigma_delta: Check for previous readysignals")
Quoted 2 lines
Acked-by Uwe Kleine-König <[email protected]>Signed-off-by Radu Sabau <[email protected]>Actually - dropped again. I forgot to check Sashiko.
(Note please do this yourself in future and reply to the patch if changes are needed). It raises some concerns about devices that don't provide the callbacks and hence won't ever use thatkeep_cs_asserted= false callback.
Quoted 8 lines
I'm struggling a bit on how the max11205 works at all as there seems to be a status register read on a device which claims to have no registers.
ad_sigma_delta_clear_pending_event()as the binding suggests this device doesn't have adrdy_gpioAnyhow, please take a look at the feedback and if it's wrong please provide an explanation of why in this thread.
Hi Jonathan,
First of all sorry for forgetting about Sashiko. I had a look at max11205 and it seems like the device doesn't have a CS so therefore the concern Sashiko raises regarding CS may not be valid, I will make sure to mention that in the commit message.
On the other hand, I see the IC has a shared pin for DRDY and DOUT and the bindings specify some interrupt though no specific rdy-gpios are mentioned there. The device reads a register that doesn't exist which in this case means it blindly clocks out whatever comes on MISO...
However I may have a fix for this and would appear in a second commit.
In clear_pending_event where rdy_gpiod is checked there could be yet another else branch that could simply return 0 and here is why I think this would work:
Since the IRQ is requested with IRQF_NO_AUTOEN and IRQ_DISABLE_UNLAZY, the latter keeps the IRQ hardware-unmasked even while software-disabled, so any falling edge from a completed conversion is latched by the IRQ controller. When ad_sd_enable_irq() is subsequently called, the latched edge fires immediately, and ad_sd_read_reg() reads the complete stale result without any prior partial clock corruption, so the result is not read by mistake as it could currently happen.
Let me know your thoughts on this,
Radu
David Lechner
reviewerQuoted 37 lines · Radu bogdan
Quoted 3 lines
-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Tuesday, May 12, 2026 2:13 PM...
Quoted 10 lines
Quoted 1 line
Fixes 132d44dc6966 ("iio: adc: ad_sigma_delta: Check for previous readysignals")
Quoted 2 lines
Acked-by Uwe Kleine-König <[email protected]>Signed-off-by Radu Sabau <[email protected]>Actually - dropped again. I forgot to check Sashiko.
(Note please do this yourself in future and reply to the patch if changes are needed). It raises some concerns about devices that don't provide the callbacks and hence won't ever use thatkeep_cs_asserted= false callback.Quoted 8 lines
I'm struggling a bit on how the max11205 works at all as there seems to be a status register read on a device which claims to have no registers.
ad_sigma_delta_clear_pending_event()as the binding suggests this device doesn't have adrdy_gpioAnyhow, please take a look at the feedback and if it's wrong please provide an explanation of why in this thread.
Hi Jonathan,
First of all sorry for forgetting about Sashiko. I had a look at max11205 and it seems like the device doesn't have a CS so therefore the concern Sashiko raises regarding CS may not be valid, I will make sure to mention that in the commit message.
On the other hand, I see the IC has a shared pin for DRDY and DOUT and the bindings specify some interrupt though no specific rdy-gpios are mentioned there. The device reads a register that doesn't exist which in this case means it blindly clocks out whatever comes on MISO...
Quoted 6 lines
However I may have a fix for this and would appear in a second commit.
Inclear_pending_eventwhererdy_gpiodis checked there could be yet another else branch that could simply return 0 and here is why I think this would work:Since the IRQ is requested with
IRQF_NO_AUTOENandIRQ_DISABLE_UNLAZY, the latter keeps the IRQ hardware-unmasked even while software-disabled, so any falling edge
This should depend on the IRQ controller. There are some past discussions on this on the mailing list. The ideal behavior should be that if the IRQ controller can fully disable the interrupt so that we don't get the spurious interrupt on enable (from the normal SPI data, not DRDY). If the interrupt controller can't do this, then it requires the rdy-gpios to be able to distinguish DRDY from SPI data.
I have used this on ad7173 on a ZedBoard without rdy-gpios and the interrupt was working correctly. So unless something changed with the interrupt config in this code since the last time I was using, I would not expect to see this problem on _all_ interrupt controllers.
Quoted 8 lines
from a completed conversion is latched by the IRQ controller. When
ad_sd_enable_irq()is subsequently called, the latched edge fires immediately, andad_sd_read_reg()reads the complete stale result without any prior partial clock corruption, so the result is not read by mistake as it could currently happen.Let me know your thoughts on this,
Radu
Quoted 3 lines
-----Original Message-----
From: David Lechner <[email protected]>
Sent: Thursday, May 14, 2026 5:57 PM
...
Quoted 29 lines
Quoted 16 lines
Quoted 8 lines
I'm struggling a bit on how the max11205 works at all as there seems to be a status register read on a device which claims to have no registers.
ad_sigma_delta_clear_pending_event()as the binding suggests this device doesn't have adrdy_gpioAnyhow, please take a look at the feedback and if it's wrong please provide an explanation of why in this thread.
Hi Jonathan,
First of all sorry for forgetting about Sashiko. I had a look at max11205 and it seems like the device doesn't have a CS so therefore the concern Sashiko raises regarding CS may not be valid, I will make sure to mention that in the commit message.
Quoted 8 lines
On the other hand, I see the IC has a shared pin for DRDY and DOUT and the bindings specify some interrupt though no specific rdy-gpios are mentioned there. The device reads a register that doesn't exist which in this case means it blindly clocks out whatever comes on MISO...
However I may have a fix for this and would appear in a second commit. In
clear_pending_eventwhererdy_gpiodis checked there could be yet another else branch that could simply return 0 and here is why I think thiswould work:
Quoted 2 lines
Since the IRQ is requested with
IRQF_NO_AUTOENandIRQ_DISABLE_UNLAZY,the latter
Quoted 1 line
keeps the IRQ hardware-unmasked even while software-disabled, so any
Quoted 9 lines
falling edge
This should depend on the IRQ controller. There are some past discussions on this on the mailing list. The ideal behavior should be that if the IRQ controller can fully disable the interrupt so that we don't get the spurious interrupt on enable (from the normal SPI data, not DRDY). If the interrupt controller can't do this, then it requires the rdy-gpios to be able to distinguish DRDY from SPI data.
rdy-gpios added to yaml of devices that don’t have them and also don't have registers is a solution too. Though I think what you mean by this is that the rdy-gpios should be something optional to be added by the user depending on his IRQ controller capabilities, right? Perhaps this is the case here already.
Quoted 5 lines
I have used this on ad7173 on a ZedBoard without rdy-gpios and the interrupt was working correctly. So unless something changed with the interrupt config in this code since the last time I was using, I would not expect to see this problem on _all_ interrupt controllers.
Yes but ad7173 has registers, max11205 and few others don't. In the cases where no rdy-gpios, although registers are present or not, it "reads" the status register which in these cases means clocking 1 byte from the DOUT line, and here 2 cases appear:
1. DOUT/RDY is still high which means DOUT reads 0xFF
- "status reg" = 0xFF
- pending_event = !(0xFF & 0x80) = !(0x80) = false
- returns 0, nothing bad happens -> Works by accident
2. DOUT reads 0x00 (line LOW) , perhaps RDY dropped already.
- The 1 byte read already consumed 8 bits of the actual conversion result and data stream is already corrupted.
- "status reg" = 0x00
- pending_event = !(0x00 & 0x80) = !(0) = true
- Continues into the drain path
- kzalloc(0 + 1) -> allocates 1 byte
- memset(data + 2, 0xff, 0 - 1) -> data_read_len is unsigned int, so 0 - 1 = SIZE_MAX
- memeset of SIZE_MAX bytes -> heap corruption, kernel crash -> Worst case, but still possible
I would then say that the solutions are 1 of :
- add rdy-gpios as well where has_registers are false.
- add another else with return 0, since if the DRDY is not low, it will be after enable_irq, and if it is low, it will be triggered afterwards and clock data correctly. For these devices as far as I can tell, there should be no spurious signals, only the DRDY interrupt unless clocking data. I may be wrong though, and perhaps the rdy-gpios is the safer move, though this would mean less churn.
What do you guys think?
Thanks,
Radu
David Lechner
reviewerQuoted 56 lines · Radu bogdan
Quoted 3 lines
-----Original Message-----
From: David Lechner <[email protected]>
Sent: Thursday, May 14, 2026 5:57 PM...
Quoted 29 lines
Quoted 16 lines
Quoted 8 lines
I'm struggling a bit on how the max11205 works at all as there seems to be a status register read on a device which claims to have no registers.
ad_sigma_delta_clear_pending_event()as the binding suggests this device doesn't have adrdy_gpioAnyhow, please take a look at the feedback and if it's wrong please provide an explanation of why in this thread.
Hi Jonathan,
First of all sorry for forgetting about Sashiko. I had a look at max11205 and it seems like the device doesn't have a CS so therefore the concern Sashiko raises regarding CS may not be valid, I will make sure to mention that in the commit message.
Quoted 8 lines
On the other hand, I see the IC has a shared pin for DRDY and DOUT and the bindings specify some interrupt though no specific rdy-gpios are mentioned there. The device reads a register that doesn't exist which in this case means it blindly clocks out whatever comes on MISO...
However I may have a fix for this and would appear in a second commit. In
clear_pending_eventwhererdy_gpiodis checked there could be yet another else branch that could simply return 0 and here is why I think thiswould work:
Quoted 2 lines
Since the IRQ is requested with
IRQF_NO_AUTOENandIRQ_DISABLE_UNLAZY,the latter
Quoted 1 line
keeps the IRQ hardware-unmasked even while software-disabled, so any
Quoted 9 lines
falling edge
This should depend on the IRQ controller. There are some past discussions on this on the mailing list. The ideal behavior should be that if the IRQ controller can fully disable the interrupt so that we don't get the spurious interrupt on enable (from the normal SPI data, not DRDY). If the interrupt controller can't do this, then it requires the rdy-gpios to be able to distinguish DRDY from SPI data.
rdy-gpios added to yaml of devices that don’t have them and also don't have registers is a solution too. Though I think what you mean by this is that the rdy-gpios should be something optional to be added by the user depending on his IRQ controller capabilities, right? Perhaps this is the case here already.
Quoted 5 lines
I have used this on ad7173 on a ZedBoard without rdy-gpios and the interrupt was working correctly. So unless something changed with the interrupt config in this code since the last time I was using, I would not expect to see this problem on _all_ interrupt controllers.
Quoted 3 lines
Yes but ad7173 has registers, max11205 and few others don't. In the cases where no rdy-gpios, although registers are present or not, it "reads" the status register which in these cases means clocking 1 byte
There is already sigma_delta->info->has_registers. Why is this not used to prevent reading the status register when there are no registers?
Quoted 20 lines
from the DOUT line, and here 2 cases appear:
1. DOUT/RDY is still high which means DOUT reads
0xFF- "status reg" =
0xFF
-pending_event= !(0xFF &0x80) = !(0x80) = false
- returns 0, nothing bad happens -> Works by accident2. DOUT reads
0x00(line LOW) , perhaps RDY dropped already.- The 1 byte read already consumed 8 bits of the actual conversion result and data stream is already corrupted.
- "status reg" =0x00
-pending_event= !(0x00 &0x80) = !(0) = true
- Continues into the drain path
- kzalloc(0 + 1) -> allocates 1 byte
-memset(data + 2, 0xff, 0 - 1)->data_read_lenis unsigned int, so 0 - 1 =SIZE_MAX
- memeset ofSIZE_MAXbytes -> heap corruption, kernel crash -> Worst case, but still possible
Quoted 7 lines
I would then say that the solutions are 1 of :
- add rdy-gpios as well wherehas_registersare false.
- add another else with return 0, since if the DRDY is not low, it will be afterenable_irq, and if it is low, it will be triggered afterwards and clock data correctly. For these devices as far as I can tell, there should be no spurious signals, only the DRDY interrupt unless clocking data. I may be wrong though, and perhaps the rdy-gpios is the safer move, though this would mean less churn.
I would expect the need for rdy-gpios to be the same whether not not the chip has registers (only depends on the interrupt controller).
Quoted 6 lines
What do you guys think?
Thanks,
Radu
Quoted 77 lines
-----Original Message-----
From: David Lechner <[email protected]>
Sent: Friday, May 15, 2026 4:27 PM
To: Sabau, Radu bogdan <[email protected]>; Jonathan Cameron <[email protected]>; Radu Sabau via B4 Relay <[email protected]>
Cc: Lars-Peter Clausen <[email protected]>; Hennerich, Michael <[email protected]>; Sa, Nuno <[email protected]>; Andy Shevchenko <[email protected]>; Uwe Kleine König <u.kleine- [email protected]>; [email protected]; linux- [email protected]
Subject: Re: [PATCH v2] iio: adc:ad_sigma_delta: fix CS held asserted after single conversion[External]
Quoted 9 lines · Radu bogdan
Quoted 3 lines
-----Original Message-----
From: David Lechner <[email protected]>
Sent: Thursday, May 14, 2026 5:57 PM...
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
I'm struggling a bit on how the max11205 works at all as there seems to be a status register read on a device which claims to have no registers.
ad_sigma_delta_clear_pending_event()as the binding suggests thisdevice
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
doesn't have a
drdy_gpioAnyhow, please take a look at the feedback and if it's wrong please
provide
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
an explanation of why in this thread.
Hi Jonathan,
First of all sorry for forgetting about Sashiko. I had a look at max11205 and
it
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
seems like the device doesn't have a CS so therefore the concern Sashiko raises regarding CS may not be valid, I will make sure to mention that in the commit message.
On the other hand, I see the IC has a shared pin for DRDY and DOUT and the bindings specify some interrupt though no specific rdy-gpios are mentioned there. The device reads a register that doesn't exist which in this case means it blindly clocks out whatever comes on MISO...
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
However I may have a fix for this and would appear in a second commit. In
clear_pending_eventwhererdy_gpiodis checked there could be yet another else branch that could simply return 0 and here is why I think thiswould work:
Quoted 2 lines
Since the IRQ is requested with
IRQF_NO_AUTOENand
IRQ_DISABLE_UNLAZY,Quoted 23 lines
Quoted 11 lines
the latter
Quoted 1 line
keeps the IRQ hardware-unmasked even while software-disabled, so any
falling edge
This should depend on the IRQ controller. There are some past discussions on this on the mailing list. The ideal behavior should be that if the IRQ controller can fully disable the interrupt so that we don't get the spurious interrupt on enable (from the normal SPI data, not DRDY). If the interrupt controller can't do this, then it requires the rdy-gpios to be able to distinguish DRDY from SPI data.
rdy-gpios added to yaml of devices that don’t have them and also don't have registers is a solution too. Though I think what you mean by this is that the rdy-gpios should be something optional to be added by the user depending on his IRQ controller capabilities, right? Perhaps this is the case here already.
Quoted 5 lines
I have used this on ad7173 on a ZedBoard without rdy-gpios and the interrupt was working correctly. So unless something changed with the interrupt config in this code since the last time I was using, I would not expect to see this problem on _all_ interrupt controllers.
Quoted 7 lines
Quoted 3 lines
Yes but ad7173 has registers, max11205 and few others don't. In the cases where no rdy-gpios, although registers are present or not, it "reads" the status register which in these cases means clocking 1 byte
There is already
sigma_delta->info->has_registers. Why is this not used to prevent reading the status register when there are no registers?
That's pretty much what that new 'else' would be doing, handling devices without registers.
Quoted 29 lines
Quoted 11 lines
from the DOUT line, and here 2 cases appear:
1. DOUT/RDY is still high which means DOUT reads
0xFF- "status reg" =
0xFF
-pending_event= !(0xFF &0x80) = !(0x80) = false
- returns 0, nothing bad happens -> Works by accident2. DOUT reads
0x00(line LOW) , perhaps RDY dropped already.Quoted 7 lines
- The 1 byte read already consumed 8 bits of the actual conversion result and data stream is already corrupted.
- "status reg" =0x00
-pending_event= !(0x00 &0x80) = !(0) = true
- Continues into the drain path
- kzalloc(0 + 1) -> allocates 1 byte
-memset(data + 2, 0xff, 0 - 1)->data_read_lenis unsigned int, so 0 - 1 =
SIZE_MAXQuoted 1 line
- memeset of
SIZE_MAXbytes -> heap corruption, kernel crash -> Worstcase, but
Quoted 5 lines
still possible
I would then say that the solutions are 1 of :
- add rdy-gpios as well wherehas_registersare false.
- add another else with return 0, since if the DRDY is not low, it will be after
enable_irq,Quoted 1 line
and if it is low, it will be triggered afterwards and clock data correctly. For
these devices
Quoted 8 lines
Quoted 1 line
as far as I can tell, there should be no spurious signals, only the DRDY
interrupt unless
Quoted 1 line
clocking data. I may be wrong though, and perhaps the rdy-gpios is the safer
move,
Quoted 1 line
though this would mean less churn.
I would expect the need for rdy-gpios to be the same whether not not the chip has registers (only depends on the interrupt controller).
I would too, would then add rdy-gpios where needed instead.
Quoted 7 lines
Quoted 7 lines
What do you guys think?
Thanks,
Radu
Quoted 3 lines
-----Original Message-----
From: Sabau, Radu bogdan
Sent: Monday, May 18, 2026 12:38 PM\
...
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines
I would then say that the solutions are 1 of :
- add rdy-gpios as well wherehas_registersare false.
- add another else with return 0, since if the DRDY is not low, it will be after
enable_irq,Quoted 1 line
and if it is low, it will be triggered afterwards and clock data correctly. For
these devices
Quoted 1 line
as far as I can tell, there should be no spurious signals, only the DRDY
interrupt unless
Quoted 1 line
clocking data. I may be wrong though, and perhaps the rdy-gpios is the
Quoted 9 lines
safer
Quoted 5 lines
move,
Quoted 1 line
though this would mean less churn.
I would expect the need for rdy-gpios to be the same whether not not the chip has registers (only depends on the interrupt controller).
I would too, would then add rdy-gpios where needed instead.
Sorry for the confusion, I misread your reply. You're right - the need for rdy-gpios depends on the interrupt controller, not on whether the device has registers. Since register-based devices work correctly without rdy-gpios, the same applies to non-register devices. Adding rdy-gpios selectively for has_registers = false devices would be inconsistent.
The correct fix is the else { return 0; } path in ad_sigma_delta_clear_pending_event(), which prevents the spurious SPI read for devices with neither registers nor rdy-gpiod. I'll keep the driver fix and drop the idea of touching the bindings.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
What do you guys think?
Thanks,
Radu