Re: [PATCH 06/10] iio: dac: ad5686: acquire lock when doing powerdown control

From: Jonathan Cameron

Date: Sun Apr 26 2026 - 09:47:30 EST


On Sun, 26 Apr 2026 09:38:07 +0100
Rodrigo Alencar via B4 Relay <devnull+rodrigo.alencar.analog.com@xxxxxxxxxx> wrote:

> From: Rodrigo Alencar <rodrigo.alencar@xxxxxxxxxx>
>
> Protect access of pwr_down_mode and pwr_down_mask fields with existing
> mutex lock. This issue exists since the ad5686 driver was first
> introduced.

This doesn't say what the issue is. You definitely need to mention
why those two elements need protecting.

> Acquire mutex with guard(mutex)() throughout for consistency,
> which allows for early returns, facilitating the review of further
> changes.
>
> Fixes: c2f37c8dcadc ("iio: dac: New driver for AD5686R, AD5685R, AD5684R Digital to analog converters")

Again, fixes at start of patch set. Or given there are a few here, as
a set on their own.

> Signed-off-by: Rodrigo Alencar <rodrigo.alencar@xxxxxxxxxx>
> ---
> drivers/iio/dac/ad5686.c | 27 ++++++++++++++-------------
> 1 file changed, 14 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
> index 843e425f656f..c7d5ee344a6f 100644
> --- a/drivers/iio/dac/ad5686.c
> +++ b/drivers/iio/dac/ad5686.c

> @@ -163,25 +170,19 @@ static int ad5686_write_raw(struct iio_dev *indio_dev,
> long mask)
> {
> struct ad5686_state *st = iio_priv(indio_dev);
> - int ret;
> +
> + guard(mutex)(&st->lock);

Guard changes don't appear related to the thing being fixed so
do that in a separate patch. Fine to have an intermediate state
where the fix includes guard() only in the new places the lock
is taken then a follow up patch that brings everything else in line
with that.

>
> switch (mask) {
> case IIO_CHAN_INFO_RAW:
> if (val > (1 << chan->scan_type.realbits) || val < 0)
> return -EINVAL;
>
> - mutex_lock(&st->lock);
> - ret = st->write(st,
> - AD5686_CMD_WRITE_INPUT_N_UPDATE_N,
> - chan->address,
> - val << chan->scan_type.shift);
> - mutex_unlock(&st->lock);
> - break;
> + return st->write(st, AD5686_CMD_WRITE_INPUT_N_UPDATE_N,
> + chan->address, val << chan->scan_type.shift);
> default:
> - ret = -EINVAL;
> + return -EINVAL;
> }
> -
> - return ret;
> }
>
> static const struct iio_info ad5686_info = {
>