Re: [PATCH v6 03/12] iio: dac: ad5686: acquire lock when doing powerdown control

Rodrigo Alencar
2026-05-05T14:06:35Z

On 26/05/05 03:58PM, Andy Shevchenko wrote:
> On Tue, May 05, 2026 at 01:35:04PM +0100, Rodrigo Alencar via B4 Relay wrote:
>
> > Protect access of pwr_down_mode and pwr_down_mask fields with existing
> > mutex lock. Each channel exposes their own attributes for controlling
> > powerdown modes and powerdown state. This fixes potential race conditions
> > as those the write functions perform non-atomic read-modify-write
> > operations to those pwr_down_* fields. This issue exists since the ad5686
> > driver was first introduced.
>
> ...
>
> > static ssize_t ad5686_read_dac_powerdown(struct iio_dev *indio_dev,
> > {
> > struct ad5686_state *st = iio_priv(indio_dev);
> >
> > + guard(mutex)(&st->lock);
> > +
> > return sysfs_emit(buf, "%d\n", !!(st->pwr_down_mask &
> > (0x3 << (chan->channel * 2))));
>
> Why not use ad5686_get_powerdown_mode() instead?

powerdown mode != powerdown mask. The powerdown mask controls the on-off
behavior, while the mode controls the possible values for when it is off.

> > }
>
> ...
>
> > static ssize_t ad5686_write_dac_powerdown(struct iio_dev *indio_dev,
> > if (ret)
> > return ret;
> >
> > + guard(mutex)(&st->lock);
> > +
> > if (readin)
> > st->pwr_down_mask |= (0x3 << (chan->channel * 2));
> > else
>
> Similar question here...

I suppose the above applies here as well.

> --
> With Best Regards,
> Andy Shevchenko
>
>

--
Kind regards,

Rodrigo Alencar