Re: [PATCH v4 3/3] iio: accel: bmc150: use guard(mutex) for mutex handling

From: Andy Shevchenko

Date: Mon Aug 17 2026 - 12:03:17 EST


On Mon, Aug 17, 2026 at 12:42:31AM +0100, Gabriel Rondon wrote:
> Replace manual mutex_lock()/mutex_unlock() pairs with guard(mutex) and
> scoped_guard() from cleanup.h in the functions where the critical
> section covers the whole function body or a single statement. This
> simplifies the error paths by removing the explicit unlock calls
> before returning.
>
> 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.
>
> Call sites that take and drop the mutex several times per function
> (read_raw, write_raw) or unlock through a goto label
> (buffer_postenable/predisable) are left untouched and can be converted
> separately.

...

> static irqreturn_t bmc150_accel_trigger_handler(int irq, void *p)

> struct bmc150_accel_data *data = iio_priv(indio_dev);
> int ret;
>
> - mutex_lock(&data->mutex);
> - ret = regmap_bulk_read(data->regmap, BMC150_ACCEL_REG_XOUT_L,
> - data->scan.channels, AXIS_MAX * 2);
> - mutex_unlock(&data->mutex);
> + scoped_guard(mutex, &data->mutex)
> + ret = regmap_bulk_read(data->regmap, BMC150_ACCEL_REG_XOUT_L,
> + data->scan.channels, AXIS_MAX * 2);
> if (ret < 0)
> goto err_read;

Not directly related to this change, but even in the original code what is
protected here by the mutex? data->scan.channels?

--
With Best Regards,
Andy Shevchenko