lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <17ac2fa9033104c3bf9260fbecc1c9a5b42fcbba.camel@gmail.com>
Date: Thu, 04 Dec 2025 14:42:10 +0000
From: Nuno Sá <noname.nuno@...il.com>
To: Kurt Borja <kuurtb@...il.com>, Andy Shevchenko
 <andriy.shevchenko@...el.com>,  Lars-Peter Clausen	 <lars@...afoo.de>,
 Michael Hennerich <Michael.Hennerich@...log.com>,  Jonathan Cameron	
 <jic23@...nel.org>, Benson Leung <bleung@...omium.org>, Antoniu Miclaus	
 <antoniu.miclaus@...log.com>, Gwendal Grignou <gwendal@...omium.org>, 
 Shrikant Raskar <raskar.shree97@...il.com>, Per-Daniel Olsson
 <perdaniel.olsson@...s.com>
Cc: David Lechner <dlechner@...libre.com>, Nuno Sá
	 <nuno.sa@...log.com>, Andy Shevchenko <andy@...nel.org>, Guenter Roeck
	 <groeck@...omium.org>, Jonathan Cameron <Jonathan.Cameron@...wei.com>, 
	linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org, 
	chrome-platform@...ts.linux.dev
Subject: Re: [PATCH RFC 6/6] iio: light: opt4060: Use cleanup.h for IIO locks

On Wed, 2025-12-03 at 14:18 -0500, Kurt Borja wrote:
> Simplify and drop "hacky" busy-waiting code in
> opt4060_set_driver_state() by using guard().
> 
> Signed-off-by: Kurt Borja <kuurtb@...il.com>
> ---
>  drivers/iio/light/opt4060.c | 52 +++++++++++++++------------------------------
>  1 file changed, 17 insertions(+), 35 deletions(-)
> 
> diff --git a/drivers/iio/light/opt4060.c b/drivers/iio/light/opt4060.c
> index 500899d7bd62..903963606143 100644
> --- a/drivers/iio/light/opt4060.c
> +++ b/drivers/iio/light/opt4060.c
> @@ -22,6 +22,7 @@
>  #include <linux/iio/trigger.h>
>  #include <linux/iio/trigger_consumer.h>
>  #include <linux/iio/triggered_buffer.h>
> +#include <linux/cleanup.h>
>  
>  /* OPT4060 register set */
>  #define OPT4060_RED_MSB				0x00
> @@ -302,41 +303,22 @@ 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_claim_buffer(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(indio_dev);
> -	}
> -	return ret;
> +
> +	guard(iio_device_claim)(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_using_own(indio_dev))
> +		return opt4060_set_state_common(chip, true, true);
> +

I think that if we are open coding lock(mlock) plus iio_buffer_enabled, then
iio_device_claim kind of loses it's real meaning. To me

guard(iio_device_claim)(indio_dev);

it's basically iio_dev_lock

- Nuno Sá

> +	/*
> +	 * 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);
>  }
>  
>  /*

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ