public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Raffael Raiel Trindade <raffaelraiel@usp.br>
Cc: dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
	Kim Carvalho <kim.ca@usp.br>,
	linux-iio@vger.kernel.org
Subject: Re: [PATCH v3] iio: light: vcnl4000: use lock guard()
Date: Tue, 21 Apr 2026 15:49:52 +0100	[thread overview]
Message-ID: <20260421154952.5784d2bb@jic23-huawei> (raw)
In-Reply-To: <20260420200047.102159-1-raffaelraiel@usp.br>

On Mon, 20 Apr 2026 16:59:33 -0300
Raffael Raiel Trindade <raffaelraiel@usp.br> wrote:

> From: Raffael Raiel Trindade <raffaelraiel@usp.br>
> 
> Use guard() for handling mutex lock instead of manually locking and
> unlocking. Remove gotos in error handling logic. This prevents forgotten
> locks on early exits.
> 
> Signed-off-by: Raffael Raiel Trindade <raffaelraiel@usp.br>
> Co-developed-by: Kim Carvalho <kim.ca@usp.br>
> Signed-off-by: Kim Carvalho <kim.ca@usp.br>


There are some functions in here where guard() is useful but you haven't
updated. e.g. vcnl4000_measure(), vcnl4040_write_als_it()
vcnl4040_write_als_period() and maybe more.

I don't mind a mix of guard() and non guard() but only when that is
because one approach is better suited to a particular bit of code than the other.
Here it looks like at least some other functions would benefit similar to the
changes this patch makes.

So I'd like a more complete patch.

One other thing inline.

Thanks,

Jonathan




> @@ -1480,13 +1466,13 @@ static int vcnl4040_write_event_config(struct iio_dev *indio_dev,
>  	u16 val, mask;
>  	struct vcnl4000_data *data = iio_priv(indio_dev);
>  
> -	mutex_lock(&data->vcnl4000_lock);
> +	guard(mutex)(&data->vcnl4000_lock);
>  
>  	switch (chan->type) {
>  	case IIO_LIGHT:
>  		ret = i2c_smbus_read_word_data(data->client, VCNL4200_AL_CONF);
>  		if (ret < 0)
> -			goto out;
> +			return ret;
>  
>  		mask = VCNL4040_ALS_CONF_INT_EN;
>  		if (state)
> @@ -1495,13 +1481,11 @@ static int vcnl4040_write_event_config(struct iio_dev *indio_dev,
>  			val = (ret & ~mask);
>  
>  		data->als_int = FIELD_GET(VCNL4040_ALS_CONF_INT_EN, val);
> -		ret = i2c_smbus_write_word_data(data->client, VCNL4200_AL_CONF,
> -						val);
> -		break;
> +		return i2c_smbus_write_word_data(data->client, VCNL4200_AL_CONF, val);
>  	case IIO_PROXIMITY:
>  		ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1);
>  		if (ret < 0)
> -			goto out;
> +			return ret;
>  
>  		if (dir == IIO_EV_DIR_RISING)
>  			mask = VCNL4040_PS_IF_AWAY;
> @@ -1511,17 +1495,10 @@ static int vcnl4040_write_event_config(struct iio_dev *indio_dev,
>  		val = state ? (ret | mask) : (ret & ~mask);
>  
>  		data->ps_int = FIELD_GET(VCNL4040_PS_CONF2_PS_INT, val);
> -		ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1,
> -						val);
> -		break;
> +		return i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1, val);
>  	default:
> -		break;
> +		return ret;

		return -EVINAL;

and drop the intialization of ret.

>  	}
> -
> -out:
> -	mutex_unlock(&data->vcnl4000_lock);
> -
> -	return ret;
>  }
>  
>  static irqreturn_t vcnl4040_irq_thread(int irq, void *p)


      parent reply	other threads:[~2026-04-21 14:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-20 19:59 [PATCH v3] iio: light: vcnl4000: use lock guard() Raffael Raiel Trindade
2026-04-20 20:19 ` Andy Shevchenko
2026-04-20 20:26   ` Andy Shevchenko
2026-04-20 20:40     ` Raffael Raiel Trindade
2026-04-21 14:49 ` Jonathan Cameron [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=20260421154952.5784d2bb@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=kim.ca@usp.br \
    --cc=linux-iio@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=raffaelraiel@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