From: Jonathan Cameron <jic23@kernel.org>
To: Gabriel Rondon <grondon@gmail.com>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
andy@kernel.org, nuno.sa@analog.com, dlechner@baylibre.com
Subject: Re: [PATCH v2] iio: accel: bmc150: use guard(mutex) for mutex handling
Date: Fri, 22 May 2026 16:16:55 +0100 [thread overview]
Message-ID: <20260522161655.77d40513@jic23-huawei> (raw)
In-Reply-To: <20260520101247.64458-1-grondon@gmail.com>
On Wed, 20 May 2026 11:12:47 +0100
Gabriel Rondon <grondon@gmail.com> wrote:
> Replace manual mutex_lock()/mutex_unlock() pairs with guard(mutex)
> and scoped_guard() from cleanup.h. This simplifies error paths by
> removing the need for explicit unlock calls before returning.
>
> Most converted functions hold the lock for their entire body, so
> guard(mutex) applies directly. bmc150_accel_trigger_handler() only
> holds the lock around a single register read, so scoped_guard() is
> used there to keep the lock scope unchanged.
>
> Signed-off-by: Gabriel Rondon <grondon@gmail.com>
So sashiko reports a load of preexisting issues (I haven't checked them
but it tends to be right most of the time). It spotted one issue in your
changes that i missed.
The only other 'this patch' thing was scoped_guard() + gotos. The particular
case you have is fine so don't worry about that.
> static ssize_t bmc150_accel_get_fifo_state(struct device *dev,
> @@ -860,13 +848,10 @@ static ssize_t bmc150_accel_get_fifo_state(struct device *dev,
> {
> struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> struct bmc150_accel_data *data = iio_priv(indio_dev);
> - bool state;
>
> - mutex_lock(&data->mutex);
> - state = data->fifo_mode;
This cast an integer to a bool. So 0x40 -> true.
> - mutex_unlock(&data->mutex);
> + guard(mutex)(&data->mutex);
>
> - return sysfs_emit(buf, "%d\n", state);
> + return sysfs_emit(buf, "%d\n", data->fifo_mode);
This will just print that 0x40 (in decimal) whereas should be 0 or 1.
I'd suggest data->fifo_mode ? 1 : 0 in this call.
> }
>
prev parent reply other threads:[~2026-05-22 15:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-20 10:12 Gabriel Rondon
2026-05-20 11:41 ` Stepan Ionichev
2026-05-22 15:16 ` 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=20260522161655.77d40513@jic23-huawei \
--to=jic23@kernel.org \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=grondon@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@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
all inboxes | Powered by JetHome®