]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: light: opt4060: Use IIO cleanup helpers
authorKurt Borja <kuurtb@gmail.com>
Tue, 20 Jan 2026 06:20:47 +0000 (01:20 -0500)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Thu, 22 Jan 2026 20:53:17 +0000 (20:53 +0000)
Use IIO_DEV_GUARD_CURRENT_MODE() cleanup helper to simplify and drop
busy-waiting code in opt4060_set_driver_state().

Reviewed-by: David Lechner <dlechner@baylibre.com>
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Signed-off-by: Kurt Borja <kuurtb@gmail.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/light/opt4060.c

index 8c4a1f562a832a021fd77f0a7ec30797de16d5a0..d6e915ab355d13818e4460a4de7a724145ff2eea 100644 (file)
@@ -302,41 +302,23 @@ static int opt4060_set_driver_state(struct iio_dev *indio_dev,
                                    bool continuous_irq)
 {
        struct opt4060_chip *chip = iio_priv(indio_dev);
-       int ret = 0;
-any_mode_retry:
-       if (!iio_device_try_claim_buffer_mode(indio_dev)) {
-               /*
-                * This one is a *bit* hacky. If we cannot claim buffer mode,
-                * then try direct mode so that we make sure things cannot
-                * concurrently change. And we just keep trying until we get one
-                * of the modes...
-                */
-               if (!iio_device_claim_direct(indio_dev))
-                       goto any_mode_retry;
-               /*
-                * This path means that we managed to claim direct mode. In
-                * this case the buffer isn't enabled and it's okay to leave
-                * continuous mode for sampling and/or irq.
-                */
-               ret = opt4060_set_state_common(chip, continuous_sampling,
-                                              continuous_irq);
-               iio_device_release_direct(indio_dev);
-               return ret;
-       } else {
-               /*
-                * This path means that we managed to claim buffer mode. In
-                * this case the buffer is enabled and irq and sampling must go
-                * to or remain continuous, but only if the trigger is from this
-                * device.
-                */
-               if (!iio_trigger_validate_own_device(indio_dev->trig, indio_dev))
-                       ret = opt4060_set_state_common(chip, true, true);
-               else
-                       ret = opt4060_set_state_common(chip, continuous_sampling,
-                                                      continuous_irq);
-               iio_device_release_buffer_mode(indio_dev);
-       }
-       return ret;
+
+       IIO_DEV_GUARD_CURRENT_MODE(indio_dev);
+
+       /*
+        * If we manage to claim buffer mode and we are using our own trigger,
+        * 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))
+               return opt4060_set_state_common(chip, true, true);
+
+       /*
+        * This path means that we managed to claim direct mode. In this case
+        * the buffer isn't enabled and it's okay to leave continuous mode for
+        * sampling and/or irq.
+        */
+       return opt4060_set_state_common(chip, continuous_sampling, continuous_irq);
 }
 
 /*