Re: [PATCH v5 05/15] iio: adc: ad4134: Serialize single-read operations

From: Jonathan Cameron

Date: Sat Oct 17 2026 - 15:14:27 EST


On Fri, 16 Oct 2026 22:57:47 -0300
Marcelo Schmitt <marcelo.schmitt@xxxxxxxxxx> wrote:

> Protect single-sample read operations from going wrong if two or more of
> them run concurrently. Serialize the data read operation so to avoid
> single-sample read requests disrupting each other.

Why isn't this a fix (with appropriate fixes tag)?
If nothing else comes up and you agree it should have one just
reply to this email with it.

Otherwise LGTM

>
> Reviewed-by: Nuno Sá <nuno.sa@xxxxxxxxxx>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>
> Signed-off-by: Marcelo Schmitt <marcelo.schmitt@xxxxxxxxxx>
> ---
> drivers/iio/adc/ad4134.c | 16 +++++++++++++++-
> 1 file changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/adc/ad4134.c b/drivers/iio/adc/ad4134.c
> index dc2b32c73a3a..dc4d801490db 100644
> --- a/drivers/iio/adc/ad4134.c
> +++ b/drivers/iio/adc/ad4134.c
> @@ -7,6 +7,7 @@
> #include <linux/array_size.h>
> #include <linux/bitfield.h>
> #include <linux/bitops.h>
> +#include <linux/cleanup.h>
> #include <linux/clk.h>
> #include <linux/crc8.h>
> #include <linux/delay.h>
> @@ -15,6 +16,7 @@
> #include <linux/export.h>
> #include <linux/gpio/consumer.h>
> #include <linux/module.h>
> +#include <linux/mutex.h>
> #include <linux/regmap.h>
> #include <linux/regulator/consumer.h>
> #include <linux/reset.h>
> @@ -98,6 +100,11 @@ struct ad4134_state {
> struct regmap *regmap;
> unsigned long sys_clk_hz;
> struct gpio_desc *odr_gpio;
> + /*
> + * Synchronize access to device state fields and ensure atomicity of
> + * consecutive register access operations.
> + */
> + struct mutex sync_lock;
> int refin_mv;
> /*
> * DMA (thus cache coherency maintenance) requires the transfer buffers
> @@ -257,7 +264,9 @@ static int ad4134_read_raw(struct iio_dev *indio_dev,
> int ret;
>
> switch (info) {
> - case IIO_CHAN_INFO_RAW:
> + case IIO_CHAN_INFO_RAW: {
> + guard(mutex)(&st->sync_lock);
> +
> gpiod_set_value_cansleep(st->odr_gpio, 1);
> /*
> * For slave mode gated DCLK (data sheet page 11), the minimum
> @@ -276,6 +285,7 @@ static int ad4134_read_raw(struct iio_dev *indio_dev,
> return ret;
>
> return IIO_VAL_INT;
> + }
> case IIO_CHAN_INFO_SCALE:
> *val = st->refin_mv;
> *val2 = AD4134_CHAN_PRECISION_BITS - 1;
> @@ -445,6 +455,10 @@ static int ad4134_probe(struct spi_device *spi)
> fsleep(AD4134_RESET_TIME_US);
> crc8_populate_msb(ad4134_spi_crc_table, AD4134_SPI_CRC_POLYNOM);
>
> + ret = devm_mutex_init(dev, &st->sync_lock);
> + if (ret)
> + return ret;
> +
> st->regmap = devm_regmap_init(dev, NULL, st, &ad4134_regmap_config);
> if (IS_ERR(st->regmap))
> return dev_err_probe(dev, PTR_ERR(st->regmap),