mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] iio: light: opt4060: fix inverted own trigger check
@ 2026-11-09  2:47 Jonathan Cameron
  2026-11-09 15:52 ` Nuno Sá
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2026-11-09  2:47 UTC (permalink / raw)
  To: iio, Per-Daniel Olsson, Kurt Borja
  Cc: David Lechner, Nuno Sá,
	Andy Shevchenko, linux-kernel, Jonathan Cameron, stable

From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>

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.

Fixes: 8284a4985416 ("iio: light: opt4060: Use IIO cleanup helpers")
Cc: stable@vger.kernel.org
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
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(-)

diff --git a/drivers/iio/light/opt4060.c b/drivers/iio/light/opt4060.c
index 8253a6a8bee4..1a7d429453be 100644
--- a/drivers/iio/light/opt4060.c
+++ b/drivers/iio/light/opt4060.c
@@ -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);
 
 	/*
-- 
2.56.0


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

* Re: [PATCH] iio: light: opt4060: fix inverted own trigger check
  2026-11-09  2:47 [PATCH] iio: light: opt4060: fix inverted own trigger check Jonathan Cameron
@ 2026-11-09 15:52 ` Nuno Sá
  2026-11-09 16:56   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Nuno Sá @ 2026-11-09 15:52 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: iio, Per-Daniel Olsson, Kurt Borja, David Lechner,
	Andy Shevchenko, linux-kernel, Jonathan Cameron, stable

On Mon, Nov 09, 2026 at 02:47:45AM +0000, Jonathan Cameron wrote:
> From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
> 
> 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.
> 
> Fixes: 8284a4985416 ("iio: light: opt4060: Use IIO cleanup helpers")
> Cc: stable@vger.kernel.org
> Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
> ---
> 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.
> ---

Reviewed-by: Nuno Sá <nuno.sa@analog.com>

>  drivers/iio/light/opt4060.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/light/opt4060.c b/drivers/iio/light/opt4060.c
> index 8253a6a8bee4..1a7d429453be 100644
> --- a/drivers/iio/light/opt4060.c
> +++ b/drivers/iio/light/opt4060.c
> @@ -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);
>  
>  	/*
> -- 
> 2.56.0
> 

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

* Re: [PATCH] iio: light: opt4060: fix inverted own trigger check
  2026-11-09 15:52 ` Nuno Sá
@ 2026-11-09 16:56   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2026-11-09 16:56 UTC (permalink / raw)
  To: Nuno Sá
  Cc: Jonathan Cameron, linux-iio, Per-Daniel Olsson, Kurt Borja,
	David Lechner, Andy Shevchenko, linux-kernel, stable

On Mon, 9 Nov 2026 15:52:31 +0000
Nuno Sá <nuno.sa@analog.com> wrote:

> On Mon, Nov 09, 2026 at 02:47:45AM +0000, Jonathan Cameron wrote:
> > From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
> > 
> > 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.
> > 
> > Fixes: 8284a4985416 ("iio: light: opt4060: Use IIO cleanup helpers")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
> > ---
> > 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.
> > ---  
> 
> Reviewed-by: Nuno Sá <nuno.sa@analog.com>

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

> 
> >  drivers/iio/light/opt4060.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/iio/light/opt4060.c b/drivers/iio/light/opt4060.c
> > index 8253a6a8bee4..1a7d429453be 100644
> > --- a/drivers/iio/light/opt4060.c
> > +++ b/drivers/iio/light/opt4060.c
> > @@ -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);
> >  
> >  	/*
> > -- 
> > 2.56.0
> >   


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

end of thread, other threads:[~2026-11-09 16:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-09  2:47 [PATCH] iio: light: opt4060: fix inverted own trigger check Jonathan Cameron
2026-11-09 15:52 ` Nuno Sá
2026-11-09 16:56   ` 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®