[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aYiQgW1F6jRSoGuh@smile.fi.intel.com>
Date: Sun, 8 Feb 2026 15:32:49 +0200
From: Andy Shevchenko <andriy.shevchenko@...el.com>
To: Neel Bullywon <neelb2403@...il.com>
Cc: Jonathan Cameron <jic23@...nel.org>,
David Lechner <dlechner@...libre.com>,
Nuno Sá <nuno.sa@...log.com>,
Andy Shevchenko <andy@...nel.org>, linux-iio@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v5 1/2] iio: magnetometer: bmc150_magn: use automated
cleanup for mutex
On Sat, Feb 07, 2026 at 08:16:58PM -0500, Neel Bullywon wrote:
> Use guard() and scoped_guard() to replace manual mutex lock/unlock
> calls. This simplifies error handling and ensures RAII-style cleanup.
>
> Additionally, replace msleep(5) with fsleep(5000) to allow the kernel
> to select the most appropriate delay mechanism based on duration.
Also, if you can fix checkpatch to make a suggesting for fsleep() it
would be even better, so we stop the flow of this checkpatch outdated
recommendations.
> guard() is used in read_raw, write_raw, trig_reen, trigger_set_state,
> and resume. Case blocks in read_raw and write_raw are wrapped in braces
> to ensure clear scope for the cleanup guards.
>
> scoped_guard() is used in remove, runtime_suspend, and suspend where a
> short mutex-protected scope is needed for a single function call.
>
> The trigger_handler function is left unchanged as mixing guard() with
> goto error paths can be fragile.
...
> + {
> + guard(mutex)(&data->mutex);
Hmm... This looks ugly, why not scoped_guard() to begin with?
> + ret = bmc150_magn_set_power_state(data, true);
> + if (ret < 0)
> + return ret;
>
> + ret = bmc150_magn_read_xyz(data, values);
> + if (ret < 0) {
> + bmc150_magn_set_power_state(data, false);
> + return ret;
> + }
> + *val = values[chan->scan_index];
>
> + ret = bmc150_magn_set_power_state(data, false);
> + if (ret < 0)
> + return ret;
> }
> return IIO_VAL_INT;
...
> - msleep(5);
> + fsleep(5000);
5 * USEC_PER_MSEC will tell the reader about the time and units used for
the API.
Should be in a separate change.
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists