iio: light: opt4060: fix inverted own trigger check
Subsystems (2)
Jonathan Cameron
maintainerPATCH 1/1 iio: light: opt4060: fix inverted own trigger check
From: Jonathan Cameron <[email protected]>
opt4060_set_driver_state() is meant to keep sampling and the interrupt on every conversion enabled while the buffer is in use with the driver's own trigger, as that interrupt is what fires the trigger.
When converted to use IIO_DEV_GUARD_CURRENT_MODE() the negation of iio_trigger_validate_own_device(), which returns 0 for the device's own trigger, was lost. As a result, with the driver's own trigger in use, enabling or disabling a threshold event switches the interrupt to thresholds only and buffered capture stops. With another trigger in use, the one shot conversions requested by opt4060_trigger_new_samples() are instead forced to continuous mode.
Restore the negation so the code matches the comment above it.
---
This was found by an LLM whilst doing a refactor of related code. Indeed seems there was a change of behavior in the sited patch that wasn't as intended.
--- drivers/iio/light/opt4060.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/light/opt4060.c +1 -1
@@ -310,7 +310,7 @@ static int opt4060_set_driver_state(struct iio_dev *indio_dev,* IRQ and sampling must go to or remain continuous. */ if (iio_buffer_enabled (indio_dev) && -iio_trigger_validate_own_device (indio_dev->trig, indio_dev)) + !iio_trigger_validate_own_device (indio_dev->trig, indio_dev))return opt4060_set_state_common (chip, true, true);/*
Signature · 1 line
2.56.0
Quoted 16 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
opt4060_set_driver_state()is meant to keep sampling and the interrupt on every conversion enabled while the buffer is in use with the driver's own trigger, as that interrupt is what fires the trigger.When converted to use
IIO_DEV_GUARD_CURRENT_MODE()the negation ofiio_trigger_validate_own_device(), which returns 0 for the device's own trigger, was lost. As a result, with the driver's own trigger in use, enabling or disabling a threshold event switches the interrupt to thresholds only and buffered capture stops. With another trigger in use, the one shot conversions requested byopt4060_trigger_new_samples()are instead forced to continuous mode.Restore the negation so the code matches the comment above it.
Quoted 8 lines
Fixes 8284a4985416 ("iio: light: opt4060: Use IIO cleanup helpers")Signed-off-by Jonathan Cameron <[email protected]>---
This was found by an LLM whilst doing a refactor of related code. Indeed seems there was a change of behavior in the sited patch that wasn't as intended.
---
Quoted 19 lines
drivers/iio/light/opt4060.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/light/opt4060.c +1
-1@@ -310,7 +310,7 @@ static int opt4060_set_driver_state(struct iio_dev *indio_dev,* IRQ and sampling must go to or remain continuous. */ if (iio_buffer_enabled (indio_dev) && -iio_trigger_validate_own_device (indio_dev->trig, indio_dev)) + !iio_trigger_validate_own_device (indio_dev->trig, indio_dev))return opt4060_set_state_common (chip, true, true);/* Signature · 1 line
2.56.0
Quoted 26 lines · On Mon, 9 Nov 2026 15:52:31 +0000 Nuno Sá <[email protected]> wrote:
Quoted 16 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
opt4060_set_driver_state()is meant to keep sampling and the interrupt on every conversion enabled while the buffer is in use with the driver's own trigger, as that interrupt is what fires the trigger.When converted to use
IIO_DEV_GUARD_CURRENT_MODE()the negation ofiio_trigger_validate_own_device(), which returns 0 for the device's own trigger, was lost. As a result, with the driver's own trigger in use, enabling or disabling a threshold event switches the interrupt to thresholds only and buffered capture stops. With another trigger in use, the one shot conversions requested byopt4060_trigger_new_samples()are instead forced to continuous mode.Restore the negation so the code matches the comment above it.
Quoted 8 lines
Fixes 8284a4985416 ("iio: light: opt4060: Use IIO cleanup helpers")Signed-off-by Jonathan Cameron <[email protected]>---
This was found by an LLM whilst doing a refactor of related code. Indeed seems there was a change of behavior in the sited patch that wasn't as intended.
---
Quoted 1 line
Reviewed-by Nuno Sá <[email protected]>
Fixed the linux-iio address. I'll probably post a v2 so I can pick these up as normal though.
Thanks for the review Nuno,
J
Quoted 20 lines
Quoted 20 lines
drivers/iio/light/opt4060.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/light/opt4060.c +1
-1@@ -310,7 +310,7 @@ static int opt4060_set_driver_state(struct iio_dev *indio_dev,* IRQ and sampling must go to or remain continuous. */ if (iio_buffer_enabled (indio_dev) && -iio_trigger_validate_own_device (indio_dev->trig, indio_dev)) + !iio_trigger_validate_own_device (indio_dev->trig, indio_dev))return opt4060_set_state_common (chip, true, true);/* Signature · 1 line
2.56.0
Jonathan Cameron
maintainerQuoted 29 lines · On Mon, 9 Nov 2026 08:56:31 -0800 Jonathan Cameron…
Quoted 26 lines · On Mon, 9 Nov 2026 15:52:31 +0000 Nuno Sá <[email protected]> wrote:
Quoted 24 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
opt4060_set_driver_state()is meant to keep sampling and the interrupt on every conversion enabled while the buffer is in use with the driver's own trigger, as that interrupt is what fires the trigger.When converted to use
IIO_DEV_GUARD_CURRENT_MODE()the negation ofiio_trigger_validate_own_device(), which returns 0 for the device's own trigger, was lost. As a result, with the driver's own trigger in use, enabling or disabling a threshold event switches the interrupt to thresholds only and buffered capture stops. With another trigger in use, the one shot conversions requested byopt4060_trigger_new_samples()are instead forced to continuous mode.Restore the negation so the code matches the comment above it.
Fixes 8284a4985416 ("iio: light: opt4060: Use IIO cleanup helpers")Signed-off-by Jonathan Cameron <[email protected]>---
This was found by an LLM whilst doing a refactor of related code. Indeed seems there was a change of behavior in the sited patch that wasn't as intended.
---
Quoted 6 lines
Quoted 1 line
Reviewed-by Nuno Sá <[email protected]>Fixed the linux-iio address. I'll probably post a v2 so I can pick these up as normal though.
Thanks for the review Nuno,
Similar to previous, I decided to be a bit naughty and pick it up on basis it was on LKML and this email with full content went to the right list.
Applied to the testing branch of iio.git
thanks,
Jonathan
Quoted 24 lines
J
Quoted 20 lines
Quoted 20 lines
drivers/iio/light/opt4060.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/light/opt4060.c +1
-1@@ -310,7 +310,7 @@ static int opt4060_set_driver_state(struct iio_dev *indio_dev,* IRQ and sampling must go to or remain continuous. */ if (iio_buffer_enabled (indio_dev) && -iio_trigger_validate_own_device (indio_dev->trig, indio_dev)) + !iio_trigger_validate_own_device (indio_dev->trig, indio_dev))return opt4060_set_state_common (chip, true, true);/* Signature · 1 line
2.56.0