From: Jonathan Cameron <jic23@kernel.org>
To: Advaith Neelacantan <advaith.neelacantan@gmail.com>
Cc: "Lars-Peter Clausen" <lars@metafoo.de>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
linux-iio@vger.kernel.org, linux-staging@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: iio: frequency: ad9832: use guard(mutex) for locking
Date: Mon, 20 Apr 2026 14:06:09 +0100 [thread overview]
Message-ID: <20260420140609.62887df7@jic23-huawei> (raw)
In-Reply-To: <20260411072503.106621-2-advaith.neelacantan@gmail.com>
On Sat, 11 Apr 2026 12:55:04 +0530
Advaith Neelacantan <advaith.neelacantan@gmail.com> wrote:
> Replace mutex lock/unlock pairs with
>
> guard(mutex) for automatic scope-based locking.
>
> Simplifies code by removing need to manually unlock.
>
> Signed-off-by: Advaith Neelacantan <advaith.neelacantan@gmail.com>
What everyone else has stated indeed applies, though I'm more flexible
if you are doing this part of driver cleanup that is more substantial
and touches nearby code.
However, it's buggy. Read the guidance in cleanup.h and make sure
you understand why. Note that LLVM will warn about the problem,
GCC currently does not.
> ---
> drivers/staging/iio/frequency/ad9832.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c
> index b87ea1781..73c47a049 100644
> --- a/drivers/staging/iio/frequency/ad9832.c
> +++ b/drivers/staging/iio/frequency/ad9832.c
> @@ -181,7 +181,7 @@ static ssize_t ad9832_write(struct device *dev, struct device_attribute *attr,
> if (ret)
> goto error_ret;
>
> - mutex_lock(&st->lock);
> + guard(mutex)(&st->lock);
> switch ((u32)this_attr->address) {
> case AD9832_FREQ0HM:
> case AD9832_FREQ1HM:
> @@ -239,7 +239,6 @@ static ssize_t ad9832_write(struct device *dev, struct device_attribute *attr,
> default:
> ret = -ENODEV;
> }
> - mutex_unlock(&st->lock);
>
> error_ret:
> return ret ? ret : len;
prev parent reply other threads:[~2026-04-20 13:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-11 7:25 [PATCH] staging: iio: frequency: ad9832: use guard(mutex) for locking Advaith Neelacantan
2026-04-11 8:09 ` Dan Carpenter
2026-04-11 8:53 ` Greg Kroah-Hartman
2026-04-14 12:55 ` kernel test robot
2026-04-20 13:06 ` 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=20260420140609.62887df7@jic23-huawei \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=advaith.neelacantan@gmail.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=gregkh@linuxfoundation.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--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