RE: [PATCH v11 4/6] iio: adc: ad4691: add SPI offload support

From: Sabau, Radu bogdan

Date: Mon May 18 2026 - 11:17:45 EST


> -----Original Message-----
> From: David Lechner <dlechner@xxxxxxxxxxxx>
> Sent: Saturday, May 16, 2026 8:53 PM

...

> > static ssize_t sampling_frequency_show(struct device *dev,
> > struct device_attribute *attr,
> > char *buf)
> > @@ -880,6 +1229,9 @@ static ssize_t sampling_frequency_show(struct
> device *dev,
> > struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> > struct ad4691_state *st = iio_priv(indio_dev);
> >
> > + if (st->manual_mode && st->offload)
> > + return sysfs_emit(buf, "%llu\n", READ_ONCE(st->offload-
> >trigger_hz));
>
> Why do we need READ_ONCE?
>

trigger_hz is u64 and if the target is 32-bit, a 64-bit access compiles to two 32-bit
instructions, so show() reading it without a lock and store() writing it concurrently
can produce a torn value at the compiler level. READ_ONCE/WRITE_ONCE suppress
the compiler transformations that would allow that splitting or caching. We could
have st->lock in show() instead, but that felt heavier than necessary for a single
scalar where a transiently stale-but-whole read is fine.