Re: [PATCH v2 1/2] iio: adc: mcp3564: Use guard() and scoped_guard() to manage mutex
From: Andy Shevchenko
Date: Mon Nov 23 2026 - 14:05:56 EST
On Mon, Nov 23, 2026 at 10:58:35PM +0530, Vaibhav Chahar wrote:
> Use guard(mutex) and scoped_guard() instead of manual mutex_lock() and
> mutex_unlock() calls to modernize the driver and improve mutex handling.
...
> dev_dbg(&indio_dev->dev, "%s: %d\n", __func__, mode);
Consider the patch to drop __func__ in dev_dbg() calls. If required with
Dynamic Debug it may be switched at run-rime.
...
> static int mcp3564_set_current_boost_mode(struct iio_dev *indio_dev,
> else
> adc->current_boost_mode = mode;
>
> - mutex_unlock(&adc->lock);
>
> return ret;
Now you will have double blank line(s) here and elsewhere.
...
> static ssize_t mcp3564_auto_zeroing_mux_store(struct device *dev,
> else
> adc->auto_zeroing_mux = auto_zero;
>
> - mutex_unlock(&adc->lock);
>
> return ret ? ret : len;
Consider going further and unwind this to return as soon as possible.
As you understand the whole patch has to be revisited for all of the comments.
...
> if (channel->output) {
> - mutex_lock(&adc->lock);
> + guard(mutex)(&adc->lock);
> +
> *val = mcp3564_burnout_avail[adc->burnout_mode][0];
> *val2 = mcp3564_burnout_avail[adc->burnout_mode][1];
> - mutex_unlock(&adc->lock);
> return IIO_VAL_INT_PLUS_MICRO;
> +
Stray change.
> }
...
> case IIO_CHAN_INFO_SCALE:
> - mutex_lock(&adc->lock);
> - *val = adc->scale_tbls[adc->hwgain][0];
> - *val2 = adc->scale_tbls[adc->hwgain][1];
> - mutex_unlock(&adc->lock);
> + scoped_guard(mutex, &adc->lock) {
> + *val = adc->scale_tbls[adc->hwgain][0];
> + *val2 = adc->scale_tbls[adc->hwgain][1];
> + }
Indentation issues.
> return IIO_VAL_INT_PLUS_NANO;
...
I stopped here. You must read what you send. Do not blindly copy'n'paste
AI slops!
--
With Best Regards,
Andy Shevchenko