Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: adc: ad9467: add mutex to struct ad9467_state

When calling ad9467_set_scale(), multiple calls to ad9467_spi_write()
are done which means we need to properly protect the whole operation so
we are sure we will be in a sane state if two concurrent calls occur.

Fixes: ad6797120238 ("iio: adc: ad9467: add support AD9467 ADC")
Signed-off-by: Nuno Sa <nuno.sa@analog.com>
Reviewed-by: David Lechner <dlechner@baylibre.com>
Link: https://lore.kernel.org/r/20231207-iio-backend-prep-v2-3-a4a33bc4d70e@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Nuno Sa and committed by
Jonathan Cameron
73772019 e072e149

+6 -1
+6 -1
drivers/iio/adc/ad9467.c
··· 4 4 * 5 5 * Copyright 2012-2020 Analog Devices Inc. 6 6 */ 7 - 7 + #include <linux/cleanup.h> 8 8 #include <linux/module.h> 9 + #include <linux/mutex.h> 9 10 #include <linux/device.h> 10 11 #include <linux/kernel.h> 11 12 #include <linux/slab.h> ··· 122 121 unsigned int output_mode; 123 122 124 123 struct gpio_desc *pwrdown_gpio; 124 + /* ensure consistent state obtained on multiple related accesses */ 125 + struct mutex lock; 125 126 }; 126 127 127 128 static int ad9467_spi_read(struct spi_device *spi, unsigned int reg) ··· 164 161 int ret; 165 162 166 163 if (readval == NULL) { 164 + guard(mutex)(&st->lock); 167 165 ret = ad9467_spi_write(spi, reg, writeval); 168 166 if (ret) 169 167 return ret; ··· 314 310 if (scale_val[0] != val || scale_val[1] != val2) 315 311 continue; 316 312 313 + guard(mutex)(&st->lock); 317 314 ret = ad9467_spi_write(st->spi, AN877_ADC_REG_VREF, 318 315 info->scale_table[i][1]); 319 316 if (ret < 0)