linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: dac: ad5449: Replace indio_dev->mlock with own device lock
@ 2020-05-14  9:01 Sergiu Cuciurean
  2020-05-16 15:16 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Sergiu Cuciurean @ 2020-05-14  9:01 UTC (permalink / raw)
  To: linux-kernel, linux-iio
  Cc: Sergiu Cuciurean, Lars-Peter Clausen, Michael Hennerich,
	Stefan Popa, Jonathan Cameron, Hartmut Knaack,
	Peter Meerwald-Stadler

As part of the general cleanup of indio_dev->mlock, this change replaces
it with a local lock on the device's state structure.

Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
---
 drivers/iio/dac/ad5449.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/dac/ad5449.c b/drivers/iio/dac/ad5449.c
index fed3ebaccac4..d739b10e5236 100644
--- a/drivers/iio/dac/ad5449.c
+++ b/drivers/iio/dac/ad5449.c
@@ -56,11 +56,13 @@ struct ad5449_chip_info {
  * @has_sdo:		whether the SDO line is connected
  * @dac_cache:		Cache for the DAC values
  * @data:		spi transfer buffers
+ * @lock		lock to protect the data buffer during SPI ops
  */
 struct ad5449 {
 	struct spi_device		*spi;
 	const struct ad5449_chip_info	*chip_info;
 	struct regulator_bulk_data	vref_reg[AD5449_MAX_VREFS];
+	struct mutex			lock;
 
 	bool has_sdo;
 	uint16_t dac_cache[AD5449_MAX_CHANNELS];
@@ -87,10 +89,10 @@ static int ad5449_write(struct iio_dev *indio_dev, unsigned int addr,
 	struct ad5449 *st = iio_priv(indio_dev);
 	int ret;
 
-	mutex_lock(&indio_dev->mlock);
+	mutex_lock(&st->lock);
 	st->data[0] = cpu_to_be16((addr << 12) | val);
 	ret = spi_write(st->spi, st->data, 2);
-	mutex_unlock(&indio_dev->mlock);
+	mutex_unlock(&st->lock);
 
 	return ret;
 }
@@ -112,7 +114,7 @@ static int ad5449_read(struct iio_dev *indio_dev, unsigned int addr,
 		},
 	};
 
-	mutex_lock(&indio_dev->mlock);
+	mutex_lock(&st->lock);
 	st->data[0] = cpu_to_be16(addr << 12);
 	st->data[1] = cpu_to_be16(AD5449_CMD_NOOP);
 
@@ -123,7 +125,7 @@ static int ad5449_read(struct iio_dev *indio_dev, unsigned int addr,
 	*val = be16_to_cpu(st->data[1]);
 
 out_unlock:
-	mutex_unlock(&indio_dev->mlock);
+	mutex_unlock(&st->lock);
 	return ret;
 }
 
@@ -302,6 +304,8 @@ static int ad5449_spi_probe(struct spi_device *spi)
 	indio_dev->channels = st->chip_info->channels;
 	indio_dev->num_channels = st->chip_info->num_channels;
 
+	mutex_init(&st->lock);
+
 	if (st->chip_info->has_ctrl) {
 		unsigned int ctrl = 0x00;
 		if (pdata) {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] iio: dac: ad5449: Replace indio_dev->mlock with own device lock
  2020-05-14  9:01 [PATCH] iio: dac: ad5449: Replace indio_dev->mlock with own device lock Sergiu Cuciurean
@ 2020-05-16 15:16 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2020-05-16 15:16 UTC (permalink / raw)
  To: Sergiu Cuciurean
  Cc: linux-kernel, linux-iio, Lars-Peter Clausen, Michael Hennerich,
	Stefan Popa, Hartmut Knaack, Peter Meerwald-Stadler

On Thu, 14 May 2020 12:01:49 +0300
Sergiu Cuciurean <sergiu.cuciurean@analog.com> wrote:

> As part of the general cleanup of indio_dev->mlock, this change replaces
> it with a local lock on the device's state structure.
> 
> Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
Applied.

Thanks,

J
> ---
>  drivers/iio/dac/ad5449.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/dac/ad5449.c b/drivers/iio/dac/ad5449.c
> index fed3ebaccac4..d739b10e5236 100644
> --- a/drivers/iio/dac/ad5449.c
> +++ b/drivers/iio/dac/ad5449.c
> @@ -56,11 +56,13 @@ struct ad5449_chip_info {
>   * @has_sdo:		whether the SDO line is connected
>   * @dac_cache:		Cache for the DAC values
>   * @data:		spi transfer buffers
> + * @lock		lock to protect the data buffer during SPI ops
>   */
>  struct ad5449 {
>  	struct spi_device		*spi;
>  	const struct ad5449_chip_info	*chip_info;
>  	struct regulator_bulk_data	vref_reg[AD5449_MAX_VREFS];
> +	struct mutex			lock;
>  
>  	bool has_sdo;
>  	uint16_t dac_cache[AD5449_MAX_CHANNELS];
> @@ -87,10 +89,10 @@ static int ad5449_write(struct iio_dev *indio_dev, unsigned int addr,
>  	struct ad5449 *st = iio_priv(indio_dev);
>  	int ret;
>  
> -	mutex_lock(&indio_dev->mlock);
> +	mutex_lock(&st->lock);
>  	st->data[0] = cpu_to_be16((addr << 12) | val);
>  	ret = spi_write(st->spi, st->data, 2);
> -	mutex_unlock(&indio_dev->mlock);
> +	mutex_unlock(&st->lock);
>  
>  	return ret;
>  }
> @@ -112,7 +114,7 @@ static int ad5449_read(struct iio_dev *indio_dev, unsigned int addr,
>  		},
>  	};
>  
> -	mutex_lock(&indio_dev->mlock);
> +	mutex_lock(&st->lock);
>  	st->data[0] = cpu_to_be16(addr << 12);
>  	st->data[1] = cpu_to_be16(AD5449_CMD_NOOP);
>  
> @@ -123,7 +125,7 @@ static int ad5449_read(struct iio_dev *indio_dev, unsigned int addr,
>  	*val = be16_to_cpu(st->data[1]);
>  
>  out_unlock:
> -	mutex_unlock(&indio_dev->mlock);
> +	mutex_unlock(&st->lock);
>  	return ret;
>  }
>  
> @@ -302,6 +304,8 @@ static int ad5449_spi_probe(struct spi_device *spi)
>  	indio_dev->channels = st->chip_info->channels;
>  	indio_dev->num_channels = st->chip_info->num_channels;
>  
> +	mutex_init(&st->lock);
> +
>  	if (st->chip_info->has_ctrl) {
>  		unsigned int ctrl = 0x00;
>  		if (pdata) {


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-05-16 15:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-14  9:01 [PATCH] iio: dac: ad5449: Replace indio_dev->mlock with own device lock Sergiu Cuciurean
2020-05-16 15:16 ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).