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

iio: adc: ltc2947-core: do not use internal iio_dev lock

The iio_device lock is only meant for internal use. Hence define a
device local lock to protect against concurrent accesses.

While at it, properly include "mutex.h" for mutex related APIs.

Signed-off-by: Nuno Sá <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20221004134909.1692021-6-nuno.sa@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Nuno Sá and committed by
Jonathan Cameron
da8091f8 98c4fb93

+7 -2
+5 -2
drivers/iio/adc/ltc2497-core.c
··· 10 10 #include <linux/iio/iio.h> 11 11 #include <linux/iio/driver.h> 12 12 #include <linux/module.h> 13 + #include <linux/mutex.h> 13 14 #include <linux/regulator/consumer.h> 14 15 15 16 #include "ltc2497.h" ··· 82 81 83 82 switch (mask) { 84 83 case IIO_CHAN_INFO_RAW: 85 - mutex_lock(&indio_dev->mlock); 84 + mutex_lock(&ddata->lock); 86 85 ret = ltc2497core_read(ddata, chan->address, val); 87 - mutex_unlock(&indio_dev->mlock); 86 + mutex_unlock(&ddata->lock); 88 87 if (ret < 0) 89 88 return ret; 90 89 ··· 214 213 215 214 ddata->addr_prev = LTC2497_CONFIG_DEFAULT; 216 215 ddata->time_prev = ktime_get(); 216 + 217 + mutex_init(&ddata->lock); 217 218 218 219 ret = iio_device_register(indio_dev); 219 220 if (ret < 0)
+2
drivers/iio/adc/ltc2497.h
··· 12 12 struct ltc2497core_driverdata { 13 13 struct regulator *ref; 14 14 ktime_t time_prev; 15 + /* lock to protect against multiple access to the device */ 16 + struct mutex lock; 15 17 const struct ltc2497_chip_info *chip_info; 16 18 u8 addr_prev; 17 19 int (*result_and_measure)(struct ltc2497core_driverdata *ddata,