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

iio: adc: sc27xx_adc: 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-9-nuno.sa@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Nuno Sá and committed by
Jonathan Cameron
8433aa35 bb690935

+10 -4
+10 -4
drivers/iio/adc/sc27xx_adc.c
··· 4 4 #include <linux/hwspinlock.h> 5 5 #include <linux/iio/iio.h> 6 6 #include <linux/module.h> 7 + #include <linux/mutex.h> 7 8 #include <linux/nvmem-consumer.h> 8 9 #include <linux/of.h> 9 10 #include <linux/of_device.h> ··· 84 83 struct device *dev; 85 84 struct regulator *volref; 86 85 struct regmap *regmap; 86 + /* lock to protect against multiple access to the device */ 87 + struct mutex lock; 87 88 /* 88 89 * One hardware spinlock to synchronize between the multiple 89 90 * subsystems which will access the unique ADC controller. ··· 667 664 668 665 switch (mask) { 669 666 case IIO_CHAN_INFO_RAW: 670 - mutex_lock(&indio_dev->mlock); 667 + mutex_lock(&data->lock); 671 668 ret = sc27xx_adc_read(data, chan->channel, scale, &tmp); 672 - mutex_unlock(&indio_dev->mlock); 669 + mutex_unlock(&data->lock); 673 670 674 671 if (ret) 675 672 return ret; ··· 678 675 return IIO_VAL_INT; 679 676 680 677 case IIO_CHAN_INFO_PROCESSED: 681 - mutex_lock(&indio_dev->mlock); 678 + mutex_lock(&data->lock); 682 679 ret = sc27xx_adc_read_processed(data, chan->channel, scale, 683 680 &tmp); 684 - mutex_unlock(&indio_dev->mlock); 681 + mutex_unlock(&data->lock); 685 682 686 683 if (ret) 687 684 return ret; ··· 937 934 indio_dev->info = &sc27xx_info; 938 935 indio_dev->channels = sc27xx_channels; 939 936 indio_dev->num_channels = ARRAY_SIZE(sc27xx_channels); 937 + 938 + mutex_init(&sc27xx_data->lock); 939 + 940 940 ret = devm_iio_device_register(dev, indio_dev); 941 941 if (ret) 942 942 dev_err(dev, "could not register iio (ADC)");