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: rockchip_saradc: 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>
Acked-by: Heiko Stuebner <heiko@sntech.de>
Link: https://lore.kernel.org/r/20221004134909.1692021-8-nuno.sa@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Nuno Sá and committed by
Jonathan Cameron
bb690935 d0c09264

+10 -5
+10 -5
drivers/iio/adc/rockchip_saradc.c
··· 5 5 */ 6 6 7 7 #include <linux/module.h> 8 + #include <linux/mutex.h> 8 9 #include <linux/platform_device.h> 9 10 #include <linux/interrupt.h> 10 11 #include <linux/io.h> ··· 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 int uv_vref; 54 55 struct reset_control *reset; 55 56 const struct rockchip_saradc_data *data; ··· 97 94 98 95 switch (mask) { 99 96 case IIO_CHAN_INFO_RAW: 100 - mutex_lock(&indio_dev->mlock); 97 + mutex_lock(&info->lock); 101 98 102 99 ret = rockchip_saradc_conversion(info, chan); 103 100 if (ret) { 104 101 rockchip_saradc_power_down(info); 105 - mutex_unlock(&indio_dev->mlock); 102 + mutex_unlock(&info->lock); 106 103 return ret; 107 104 } 108 105 109 106 *val = info->last_val; 110 - mutex_unlock(&indio_dev->mlock); 107 + mutex_unlock(&info->lock); 111 108 return IIO_VAL_INT; 112 109 case IIO_CHAN_INFO_SCALE: 113 110 *val = info->uv_vref / 1000; ··· 273 270 int ret; 274 271 int i, j = 0; 275 272 276 - mutex_lock(&i_dev->mlock); 273 + mutex_lock(&info->lock); 277 274 278 275 for_each_set_bit(i, i_dev->active_scan_mask, i_dev->masklength) { 279 276 const struct iio_chan_spec *chan = &i_dev->channels[i]; ··· 290 287 291 288 iio_push_to_buffers_with_timestamp(i_dev, &data, iio_get_time_ns(i_dev)); 292 289 out: 293 - mutex_unlock(&i_dev->mlock); 290 + mutex_unlock(&info->lock); 294 291 295 292 iio_trigger_notify_done(i_dev->trig); 296 293 ··· 480 477 info); 481 478 if (ret) 482 479 return ret; 480 + 481 + mutex_init(&info->lock); 483 482 484 483 return devm_iio_device_register(&pdev->dev, indio_dev); 485 484 }