Re: [PATCH v4 1/2] staging: iio: adc: ad7816: Serialize SPI read operations
From: Joshua Crofts
Date: Sun Sep 06 2026 - 10:12:56 EST
On Sun, 6 Sep 2026 14:40:48 +0300
Abdelnasser Hussein <abdelnasserhussein11@xxxxxxxxx> wrote:
> Add a mutex to serialize SPI read operations and prevent data corruption. Used guard(mutex) and devm_mutex_init() for safer and automatic cleanup.
> Signed-off-by: Abdelnasser Hussein <abdelnasserhussein11@xxxxxxxxx>
> ---
> drivers/staging/iio/adc/ad7816.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c
> index 0e32a2295990..ab80b3a889bb 100644
> --- a/drivers/staging/iio/adc/ad7816.c
> +++ b/drivers/staging/iio/adc/ad7816.c
> @@ -14,6 +14,8 @@
> #include <linux/list.h>
> #include <linux/spi/spi.h>
> #include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/cleanup.h>
>
> #include <linux/iio/iio.h>
> #include <linux/iio/sysfs.h>
> @@ -65,7 +67,8 @@ static int ad7816_spi_read(struct ad7816_chip_info *chip, u16 *data)
> {
> struct spi_device *spi_dev = chip->spi_dev;
> int ret;
> - __be16 buf;
> +
> + guard(mutex)(&chip->lock);
Actually, I thought I was going crazy when this compiled, only to realize
you added the mutex in patch 2. Compiling with only this patch applied yields
10+ errors. Each patch must be atomic and cannot break the build, even if the
entire applied series compiles correctly.
Please revisit this.
--
Kind regards,
Joshua Crofts