diff mbox series

[v2,06/16] iio: adc: meson_saradc: do not use internal iio_dev lock

Message ID 20221004134909.1692021-7-nuno.sa@analog.com (mailing list archive)
State Superseded
Headers show
Series Make 'mlock' really private | expand

Commit Message

Nuno Sa Oct. 4, 2022, 1:48 p.m. UTC
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: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
---
 drivers/iio/adc/meson_saradc.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Comments

Jonathan Cameron Oct. 9, 2022, 12:01 p.m. UTC | #1
On Tue, 4 Oct 2022 15:48:59 +0200
Nuno Sá <nuno.sa@analog.com> wrote:

> 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: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Applied to the togreg branch of iio.git and pushed out (shortly) as testing
for 0-day etc to take a look.

Note I'll be rebasing on rc1 once it's out.

Thanks,

Jonathan

> ---
>  drivers/iio/adc/meson_saradc.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c
> index 1a68b099d323..85b6826cc10c 100644
> --- a/drivers/iio/adc/meson_saradc.c
> +++ b/drivers/iio/adc/meson_saradc.c
> @@ -12,6 +12,7 @@
>  #include <linux/io.h>
>  #include <linux/iio/iio.h>
>  #include <linux/module.h>
> +#include <linux/mutex.h>
>  #include <linux/nvmem-consumer.h>
>  #include <linux/interrupt.h>
>  #include <linux/of.h>
> @@ -276,6 +277,8 @@ struct meson_sar_adc_priv {
>  	struct clk				*adc_div_clk;
>  	struct clk_divider			clk_div;
>  	struct completion			done;
> +	/* lock to protect against multiple access to the device */
> +	struct mutex				lock;
>  	int					calibbias;
>  	int					calibscale;
>  	struct regmap				*tsc_regmap;
> @@ -486,7 +489,7 @@ static int meson_sar_adc_lock(struct iio_dev *indio_dev)
>  	struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
>  	int val, ret;
>  
> -	mutex_lock(&indio_dev->mlock);
> +	mutex_lock(&priv->lock);
>  
>  	if (priv->param->has_bl30_integration) {
>  		/* prevent BL30 from using the SAR ADC while we are using it */
> @@ -504,7 +507,7 @@ static int meson_sar_adc_lock(struct iio_dev *indio_dev)
>  						      !(val & MESON_SAR_ADC_DELAY_BL30_BUSY),
>  						      1, 10000);
>  		if (ret) {
> -			mutex_unlock(&indio_dev->mlock);
> +			mutex_unlock(&priv->lock);
>  			return ret;
>  		}
>  	}
> @@ -521,7 +524,7 @@ static void meson_sar_adc_unlock(struct iio_dev *indio_dev)
>  		regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY,
>  				   MESON_SAR_ADC_DELAY_KERNEL_BUSY, 0);
>  
> -	mutex_unlock(&indio_dev->mlock);
> +	mutex_unlock(&priv->lock);
>  }
>  
>  static void meson_sar_adc_clear_fifo(struct iio_dev *indio_dev)
> @@ -1250,6 +1253,8 @@ static int meson_sar_adc_probe(struct platform_device *pdev)
>  	if (ret)
>  		goto err;
>  
> +	mutex_init(&priv->lock);
> +
>  	ret = meson_sar_adc_hw_enable(indio_dev);
>  	if (ret)
>  		goto err;
diff mbox series

Patch

diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c
index 1a68b099d323..85b6826cc10c 100644
--- a/drivers/iio/adc/meson_saradc.c
+++ b/drivers/iio/adc/meson_saradc.c
@@ -12,6 +12,7 @@ 
 #include <linux/io.h>
 #include <linux/iio/iio.h>
 #include <linux/module.h>
+#include <linux/mutex.h>
 #include <linux/nvmem-consumer.h>
 #include <linux/interrupt.h>
 #include <linux/of.h>
@@ -276,6 +277,8 @@  struct meson_sar_adc_priv {
 	struct clk				*adc_div_clk;
 	struct clk_divider			clk_div;
 	struct completion			done;
+	/* lock to protect against multiple access to the device */
+	struct mutex				lock;
 	int					calibbias;
 	int					calibscale;
 	struct regmap				*tsc_regmap;
@@ -486,7 +489,7 @@  static int meson_sar_adc_lock(struct iio_dev *indio_dev)
 	struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
 	int val, ret;
 
-	mutex_lock(&indio_dev->mlock);
+	mutex_lock(&priv->lock);
 
 	if (priv->param->has_bl30_integration) {
 		/* prevent BL30 from using the SAR ADC while we are using it */
@@ -504,7 +507,7 @@  static int meson_sar_adc_lock(struct iio_dev *indio_dev)
 						      !(val & MESON_SAR_ADC_DELAY_BL30_BUSY),
 						      1, 10000);
 		if (ret) {
-			mutex_unlock(&indio_dev->mlock);
+			mutex_unlock(&priv->lock);
 			return ret;
 		}
 	}
@@ -521,7 +524,7 @@  static void meson_sar_adc_unlock(struct iio_dev *indio_dev)
 		regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY,
 				   MESON_SAR_ADC_DELAY_KERNEL_BUSY, 0);
 
-	mutex_unlock(&indio_dev->mlock);
+	mutex_unlock(&priv->lock);
 }
 
 static void meson_sar_adc_clear_fifo(struct iio_dev *indio_dev)
@@ -1250,6 +1253,8 @@  static int meson_sar_adc_probe(struct platform_device *pdev)
 	if (ret)
 		goto err;
 
+	mutex_init(&priv->lock);
+
 	ret = meson_sar_adc_hw_enable(indio_dev);
 	if (ret)
 		goto err;