public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Pedro Barletta Gennari <pedro.pbg@usp.br>
Cc: jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com,
	andy@kernel.org, linux-iio@vger.kernel.org
Subject: Re: [PATCH] iio: light: iqs621-als: use lock guards
Date: Mon, 20 Apr 2026 11:45:46 +0300	[thread overview]
Message-ID: <aeXnujb9-aui4ArO@ashevche-desk.local> (raw)
In-Reply-To: <20260419213202.68356-1-pedro.pbg@usp.br>

On Sun, Apr 19, 2026 at 06:31:23PM -0300, Pedro Barletta Gennari wrote:
> Use guard(mutex)() for handling mutex lock instead of
> manually locking and unlocking the mutex. This prevents forgotten
> locks due to early exits and remove the need of gotos.

...

> @@ -15,6 +15,7 @@
>  #include <linux/notifier.h>
>  #include <linux/platform_device.h>
>  #include <linux/regmap.h>
> +#include <linux/cleanup.h>

Keep the list ordered.

...

>  		ret = iqs621_als_init(iqs621_als);
>  		if (ret) {
>  			dev_err(indio_dev->dev.parent,
>  				"Failed to re-initialize device: %d\n", ret);
> -			ret = NOTIFY_BAD;
> +			return NOTIFY_BAD;
>  		} else {

Now 'else' is redundant.

> -			ret = NOTIFY_OK;
> +			return NOTIFY_OK;
>  		}
> -
> -		goto err_mutex;

...

>  	struct iqs621_als_private *iqs621_als = iio_priv(indio_dev);

>  	int ret = IIO_VAL_INT;

Drop it, use the value explicitly inline in each of the cases below.

>  
> -	mutex_lock(&iqs621_als->lock);
> +	guard(mutex)(&iqs621_als->lock);
>  
>  	switch (dir) {
>  	case IIO_EV_DIR_RISING:
>  		*val = iqs621_als->thresh_light * 16;
> -		break;
> +		return ret;
>  
>  	case IIO_EV_DIR_FALLING:
>  		*val = iqs621_als->thresh_dark * 4;
> -		break;
> +		return ret;
>  
>  	case IIO_EV_DIR_EITHER:
>  		if (iqs621_als->ir_flags_mask == IQS622_IR_FLAGS_TOUCH)
>  			*val = iqs621_als->thresh_prox * 4;
>  		else
>  			*val = iqs621_als->thresh_prox;
> -		break;
> +		return ret;
>  
>  	default:
> -		ret = -EINVAL;
> +		return -EINVAL;
>  	}

-- 
With Best Regards,
Andy Shevchenko



      reply	other threads:[~2026-04-20  8:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-19 21:31 [PATCH] iio: light: iqs621-als: use lock guards Pedro Barletta Gennari
2026-04-20  8:45 ` Andy Shevchenko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aeXnujb9-aui4ArO@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=pedro.pbg@usp.br \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox