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

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

authored by

Nuno Sá and committed by
Jonathan Cameron
98c4fb93 7dde7ec2

+8 -3
+8 -3
drivers/iio/adc/lpc32xx_adc.c
··· 15 15 #include <linux/io.h> 16 16 #include <linux/module.h> 17 17 #include <linux/mod_devicetable.h> 18 + #include <linux/mutex.h> 18 19 #include <linux/platform_device.h> 19 20 #include <linux/regulator/consumer.h> 20 21 ··· 50 49 struct clk *clk; 51 50 struct completion completion; 52 51 struct regulator *vref; 52 + /* lock to protect against multiple access to the device */ 53 + struct mutex lock; 53 54 54 55 u32 value; 55 56 }; ··· 67 64 68 65 switch (mask) { 69 66 case IIO_CHAN_INFO_RAW: 70 - mutex_lock(&indio_dev->mlock); 67 + mutex_lock(&st->lock); 71 68 ret = clk_prepare_enable(st->clk); 72 69 if (ret) { 73 - mutex_unlock(&indio_dev->mlock); 70 + mutex_unlock(&st->lock); 74 71 return ret; 75 72 } 76 73 /* Measurement setup */ ··· 83 80 wait_for_completion(&st->completion); /* set by ISR */ 84 81 clk_disable_unprepare(st->clk); 85 82 *val = st->value; 86 - mutex_unlock(&indio_dev->mlock); 83 + mutex_unlock(&st->lock); 87 84 88 85 return IIO_VAL_INT; 89 86 ··· 203 200 iodev->info = &lpc32xx_adc_iio_info; 204 201 iodev->modes = INDIO_DIRECT_MODE; 205 202 iodev->num_channels = ARRAY_SIZE(lpc32xx_adc_iio_channels); 203 + 204 + mutex_init(&st->lock); 206 205 207 206 retval = devm_iio_device_register(&pdev->dev, iodev); 208 207 if (retval)