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: vf610_adc: vf610_adc: do not use internal iio_dev lock

In order to drop the internal lock usage we needed two different things:

1) The first place where 'mlock' was being used was a typical case where
iio_device_claim_direct_mode() fits perfectly.
2) In the second case, it was being used to prevent concurrent accesses
to the device and shared data but nothing was being enforced with
regards to buffering (i.e, there was nothing preventing from changing
the conversion mode while buffering). Hence, in this case, a new lock
was introduced in the state structure.

Note that the goal is not to introduce any functional change and that is
the reason why a new lock was introduced to guarantee 2).

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

authored by

Nuno Sá and committed by
Jonathan Cameron
4e15cad8 f2bdea86

+14 -8
+14 -8
drivers/iio/adc/vf610_adc.c
··· 7 7 8 8 #include <linux/mod_devicetable.h> 9 9 #include <linux/module.h> 10 + #include <linux/mutex.h> 10 11 #include <linux/property.h> 11 12 #include <linux/platform_device.h> 12 13 #include <linux/interrupt.h> ··· 156 155 struct device *dev; 157 156 void __iomem *regs; 158 157 struct clk *clk; 158 + 159 + /* lock to protect against multiple access to the device */ 160 + struct mutex lock; 159 161 160 162 u32 vref_uv; 161 163 u32 value; ··· 471 467 { 472 468 struct vf610_adc *info = iio_priv(indio_dev); 473 469 474 - mutex_lock(&indio_dev->mlock); 470 + mutex_lock(&info->lock); 475 471 info->adc_feature.conv_mode = mode; 476 472 vf610_adc_calculate_rates(info); 477 473 vf610_adc_hw_init(info); 478 - mutex_unlock(&indio_dev->mlock); 474 + mutex_unlock(&info->lock); 479 475 480 476 return 0; 481 477 } ··· 633 629 unsigned int hc_cfg; 634 630 int ret; 635 631 636 - mutex_lock(&indio_dev->mlock); 637 - if (iio_buffer_enabled(indio_dev)) { 638 - ret = -EBUSY; 639 - goto out_unlock; 640 - } 632 + ret = iio_device_claim_direct_mode(indio_dev); 633 + if (ret) 634 + return ret; 641 635 636 + mutex_lock(&info->lock); 642 637 reinit_completion(&info->completion); 643 638 hc_cfg = VF610_ADC_ADCHC(chan->channel); 644 639 hc_cfg |= VF610_ADC_AIEN; ··· 672 669 } 673 670 674 671 out_unlock: 675 - mutex_unlock(&indio_dev->mlock); 672 + mutex_unlock(&info->lock); 673 + iio_device_release_direct_mode(indio_dev); 676 674 677 675 return ret; 678 676 } ··· 895 891 dev_err(&pdev->dev, "Couldn't initialise the buffer\n"); 896 892 goto error_iio_device_register; 897 893 } 894 + 895 + mutex_init(&info->lock); 898 896 899 897 ret = iio_device_register(indio_dev); 900 898 if (ret) {