diff mbox series

iio: adc: fsl-imx25-gcq: Replace indio_dev->mlock with own device lock

Message ID 20200826120609.203724-1-alexandru.ardelean@analog.com (mailing list archive)
State New, archived
Headers show
Series iio: adc: fsl-imx25-gcq: Replace indio_dev->mlock with own device lock | expand

Commit Message

Alexandru Ardelean Aug. 26, 2020, 12:06 p.m. UTC
From: Sergiu Cuciurean <sergiu.cuciurean@analog.com>

As part of the general cleanup of indio_dev->mlock, this change replaces
it with a local lock, to protect against any other accesses during the
reading of sample. Reading a sample requires multiple consecutive regmap
operations and a completion callback, so this requires that no other
read occurs until it completes.

Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/iio/adc/fsl-imx25-gcq.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Jonathan Cameron Aug. 29, 2020, 3:29 p.m. UTC | #1
On Wed, 26 Aug 2020 15:06:09 +0300
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:

> From: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
> 
> As part of the general cleanup of indio_dev->mlock, this change replaces
> it with a local lock, to protect against any other accesses during the
> reading of sample. Reading a sample requires multiple consecutive regmap
> operations and a completion callback, so this requires that no other
> read occurs until it completes.
> 
> Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> ---
>  drivers/iio/adc/fsl-imx25-gcq.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/adc/fsl-imx25-gcq.c b/drivers/iio/adc/fsl-imx25-gcq.c
> index 8cb51cf7a816..2a56ed0fc793 100644
> --- a/drivers/iio/adc/fsl-imx25-gcq.c
> +++ b/drivers/iio/adc/fsl-imx25-gcq.c
> @@ -38,6 +38,7 @@ struct mx25_gcq_priv {
>  	struct completion completed;
>  	struct clk *clk;
>  	int irq;
> +	struct mutex lock;

Rule 1 of locks. Every single one need documentation so that the
scope that the lock protects is clearly stated.

Otherwise patch looks fine to me.

thanks,

Jonathan


>  	struct regulator *vref[4];
>  	u32 channel_vref_mv[MX25_NUM_CFGS];
>  };
> @@ -137,9 +138,9 @@ static int mx25_gcq_read_raw(struct iio_dev *indio_dev,
>  
>  	switch (mask) {
>  	case IIO_CHAN_INFO_RAW:
> -		mutex_lock(&indio_dev->mlock);
> +		mutex_lock(&priv->lock);
>  		ret = mx25_gcq_get_raw_value(&indio_dev->dev, chan, priv, val);
> -		mutex_unlock(&indio_dev->mlock);
> +		mutex_unlock(&priv->lock);
>  		return ret;
>  
>  	case IIO_CHAN_INFO_SCALE:
> @@ -314,6 +315,8 @@ static int mx25_gcq_probe(struct platform_device *pdev)
>  		return PTR_ERR(priv->regs);
>  	}
>  
> +	mutex_init(&priv->lock);
> +
>  	init_completion(&priv->completed);
>  
>  	ret = mx25_gcq_setup_cfgs(pdev, priv);
diff mbox series

Patch

diff --git a/drivers/iio/adc/fsl-imx25-gcq.c b/drivers/iio/adc/fsl-imx25-gcq.c
index 8cb51cf7a816..2a56ed0fc793 100644
--- a/drivers/iio/adc/fsl-imx25-gcq.c
+++ b/drivers/iio/adc/fsl-imx25-gcq.c
@@ -38,6 +38,7 @@  struct mx25_gcq_priv {
 	struct completion completed;
 	struct clk *clk;
 	int irq;
+	struct mutex lock;
 	struct regulator *vref[4];
 	u32 channel_vref_mv[MX25_NUM_CFGS];
 };
@@ -137,9 +138,9 @@  static int mx25_gcq_read_raw(struct iio_dev *indio_dev,
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
-		mutex_lock(&indio_dev->mlock);
+		mutex_lock(&priv->lock);
 		ret = mx25_gcq_get_raw_value(&indio_dev->dev, chan, priv, val);
-		mutex_unlock(&indio_dev->mlock);
+		mutex_unlock(&priv->lock);
 		return ret;
 
 	case IIO_CHAN_INFO_SCALE:
@@ -314,6 +315,8 @@  static int mx25_gcq_probe(struct platform_device *pdev)
 		return PTR_ERR(priv->regs);
 	}
 
+	mutex_init(&priv->lock);
+
 	init_completion(&priv->completed);
 
 	ret = mx25_gcq_setup_cfgs(pdev, priv);