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

iio: adc: imx7d_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>
Reviewed-by: Haibo Chen <haibo.chen@nxp.com>
Link: https://lore.kernel.org/r/20221004134909.1692021-4-nuno.sa@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Nuno Sá and committed by
Jonathan Cameron
7dde7ec2 ed3aa671

+9 -5
+9 -5
drivers/iio/adc/imx7d_adc.c
··· 13 13 #include <linux/kernel.h> 14 14 #include <linux/mod_devicetable.h> 15 15 #include <linux/module.h> 16 + #include <linux/mutex.h> 16 17 #include <linux/platform_device.h> 17 18 #include <linux/regulator/consumer.h> 18 19 ··· 109 108 struct device *dev; 110 109 void __iomem *regs; 111 110 struct clk *clk; 112 - 111 + /* lock to protect against multiple access to the device */ 112 + struct mutex lock; 113 113 u32 vref_uv; 114 114 u32 value; 115 115 u32 channel; ··· 295 293 296 294 switch (mask) { 297 295 case IIO_CHAN_INFO_RAW: 298 - mutex_lock(&indio_dev->mlock); 296 + mutex_lock(&info->lock); 299 297 reinit_completion(&info->completion); 300 298 301 299 channel = chan->channel & 0x03; ··· 305 303 ret = wait_for_completion_interruptible_timeout 306 304 (&info->completion, IMX7D_ADC_TIMEOUT); 307 305 if (ret == 0) { 308 - mutex_unlock(&indio_dev->mlock); 306 + mutex_unlock(&info->lock); 309 307 return -ETIMEDOUT; 310 308 } 311 309 if (ret < 0) { 312 - mutex_unlock(&indio_dev->mlock); 310 + mutex_unlock(&info->lock); 313 311 return ret; 314 312 } 315 313 316 314 *val = info->value; 317 - mutex_unlock(&indio_dev->mlock); 315 + mutex_unlock(&info->lock); 318 316 return IIO_VAL_INT; 319 317 320 318 case IIO_CHAN_INFO_SCALE: ··· 532 530 ret = devm_add_action_or_reset(dev, __imx7d_adc_disable, dev); 533 531 if (ret) 534 532 return ret; 533 + 534 + mutex_init(&info->lock); 535 535 536 536 ret = devm_iio_device_register(dev, indio_dev); 537 537 if (ret) {