[PATCH 04/15] iio: adc: imx7d_adc: do not use internal iio_dev lock

Jonathan Cameron jic23 at kernel.org
Sat Sep 24 08:26:22 PDT 2022


On Tue, 20 Sep 2022 13:28:10 +0200
Nuno Sá <nuno.sa at analog.com> wrote:

> The iio_device lock is only meant for internal use. Hence define a
> device local lock to protect against concurrent accesses.

Mention the mutex.h include.  Technically it's an unrelated (good) change.
Definitely not worth a separate patch however so just mention it in the
description.

> 
> Signed-off-by: Nuno Sá <nuno.sa at analog.com>
> ---
>  drivers/iio/adc/imx7d_adc.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/iio/adc/imx7d_adc.c b/drivers/iio/adc/imx7d_adc.c
> index 86caff1d006b..fa19f5e09079 100644
> --- a/drivers/iio/adc/imx7d_adc.c
> +++ b/drivers/iio/adc/imx7d_adc.c
> @@ -13,6 +13,7 @@
>  #include <linux/kernel.h>
>  #include <linux/mod_devicetable.h>
>  #include <linux/module.h>
> +#include <linux/mutex.h>
>  #include <linux/platform_device.h>
>  #include <linux/regulator/consumer.h>
>  
> @@ -108,7 +109,8 @@ struct imx7d_adc {
>  	struct device *dev;
>  	void __iomem *regs;
>  	struct clk *clk;
> -
> +	/* lock to protect against multiple access to the device */
> +	struct mutex lock;
>  	u32 vref_uv;
>  	u32 value;
>  	u32 channel;
> @@ -293,7 +295,7 @@ static int imx7d_adc_read_raw(struct iio_dev *indio_dev,
>  
>  	switch (mask) {
>  	case IIO_CHAN_INFO_RAW:
> -		mutex_lock(&indio_dev->mlock);
> +		mutex_lock(&info->lock);
>  		reinit_completion(&info->completion);
>  
>  		channel = chan->channel & 0x03;
> @@ -303,16 +305,16 @@ static int imx7d_adc_read_raw(struct iio_dev *indio_dev,
>  		ret = wait_for_completion_interruptible_timeout
>  				(&info->completion, IMX7D_ADC_TIMEOUT);
>  		if (ret == 0) {
> -			mutex_unlock(&indio_dev->mlock);
> +			mutex_unlock(&info->lock);
>  			return -ETIMEDOUT;
>  		}
>  		if (ret < 0) {
> -			mutex_unlock(&indio_dev->mlock);
> +			mutex_unlock(&info->lock);
>  			return ret;
>  		}
>  
>  		*val = info->value;
> -		mutex_unlock(&indio_dev->mlock);
> +		mutex_unlock(&info->lock);
>  		return IIO_VAL_INT;
>  
>  	case IIO_CHAN_INFO_SCALE:
> @@ -487,6 +489,7 @@ static int imx7d_adc_probe(struct platform_device *pdev)
>  
>  	info = iio_priv(indio_dev);
>  	info->dev = dev;
> +	mutex_init(&info->lock);
>  
>  	info->regs = devm_platform_ioremap_resource(pdev, 0);
>  	if (IS_ERR(info->regs))




More information about the linux-arm-kernel mailing list