From: Jonathan Cameron <jic23@kernel.org>
To: lauraarakaki <lauraarakaki23@gmail.com>
Cc: dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
linux-iio@vger.kernel.org
Subject: Re: [PATCH] iio: temperature: tsys02d: Use guard(mutex) in tsys02d_write_raw()
Date: Tue, 21 Apr 2026 18:50:19 +0100 [thread overview]
Message-ID: <20260421185019.64411e62@jic23-huawei> (raw)
In-Reply-To: <20260421154007.1114389-1-lauraarakaki23@gmail.com>
On Tue, 21 Apr 2026 12:40:01 -0300
lauraarakaki <lauraarakaki23@gmail.com> wrote:
> Replace the manual mutex_lock()/mutex_unlock() pair in
> tsys02d_write_raw() with guard(mutex)() from the scope-based
> cleanup helpers (include/linux/cleanup.h).
>
Hi and welcome to IIO.
The wrap of this message is rather short. Normally we go
for 75 characters for a commit description.
> The previous code stored the return value of
> ms_sensors_write_resolution() in a local variable solely to
> bridge the gap between the manual mutex_unlock() call and the
> return statement. Using guard(mutex)() removes the need for
> both the intermediate variable and the explicit unlock call,
> since the mutex is released automatically when the function
> goes out of scope.
This paragraph is unnecessary detail.
>
> No functional change intended.
>
> Signed-off-by: lauraarakaki <lauraarakaki23@gmail.com>
> ---
> drivers/iio/temperature/tsys02d.c | 11 ++++-------
> 1 file changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/iio/temperature/tsys02d.c b/drivers/iio/temperature/tsys02d.c
> index 0cad27205667..55a55f2f4663 100644
> --- a/drivers/iio/temperature/tsys02d.c
> +++ b/drivers/iio/temperature/tsys02d.c
> @@ -10,6 +10,7 @@
> * http://www.meas-spec.com/downloads/Digital_Sensor_TSYS02D.pdf
> */
>
> +#include <linux/cleanup.h>
> #include <linux/init.h>
> #include <linux/device.h>
> #include <linux/kernel.h>
> @@ -62,7 +63,7 @@ static int tsys02d_write_raw(struct iio_dev *indio_dev,
> int val, int val2, long mask)
> {
> struct ms_ht_dev *dev_data = iio_priv(indio_dev);
> - int i, ret;
> + int i;
>
> switch (mask) {
> case IIO_CHAN_INFO_SAMP_FREQ:
> @@ -72,17 +73,13 @@ static int tsys02d_write_raw(struct iio_dev *indio_dev,
> break;
> if (i < 0)
> return -EINVAL;
> - mutex_lock(&dev_data->lock);
> + guard(mutex)(&dev_data->lock);
Unfortunately this broken because the non obvious definition of scope
in switch case statements. You need to add {} in appropriate places.
See some similar threads from last few days.
> dev_data->res_index = i;
> - ret = ms_sensors_write_resolution(dev_data, i);
> - mutex_unlock(&dev_data->lock);
> -
> - return ret;
> + return ms_sensors_write_resolution(dev_data, i);
> default:
> return -EINVAL;
> }
> }
> -
Unrelated change. Always check for these and clean them up before posting.
> static const struct iio_chan_spec tsys02d_channels[] = {
> {
> .type = IIO_TEMP,
prev parent reply other threads:[~2026-04-21 17:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-21 15:40 [PATCH] iio: temperature: tsys02d: Use guard(mutex) in tsys02d_write_raw() lauraarakaki
2026-04-21 17:50 ` 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=20260421185019.64411e62@jic23-huawei \
--to=jic23@kernel.org \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=lauraarakaki23@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=nuno.sa@analog.com \
/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