* [PATCH] iio: dac: ad5421: Replace indio_dev->mlock with own device lock
@ 2020-05-14 9:17 Sergiu Cuciurean
2020-05-16 15:27 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: Sergiu Cuciurean @ 2020-05-14 9:17 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/ad5421.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/dac/ad5421.c b/drivers/iio/dac/ad5421.c
index 63063e85cd0a..fec27764cea8 100644
--- a/drivers/iio/dac/ad5421.c
+++ b/drivers/iio/dac/ad5421.c
@@ -62,12 +62,14 @@
* @current_range: current range which the device is configured for
* @data: spi transfer buffers
* @fault_mask: software masking of events
+ * @lock lock to protect the data buffer during SPI ops
*/
struct ad5421_state {
struct spi_device *spi;
unsigned int ctrl;
enum ad5421_current_range current_range;
unsigned int fault_mask;
+ struct mutex lock;
/*
* DMA (thus cache coherency maintenance) requires the
@@ -142,11 +144,12 @@ static int ad5421_write_unlocked(struct iio_dev *indio_dev,
static int ad5421_write(struct iio_dev *indio_dev, unsigned int reg,
unsigned int val)
{
+ struct ad5421_state *st = iio_priv(indio_dev);
int ret;
- mutex_lock(&indio_dev->mlock);
+ mutex_lock(&st->lock);
ret = ad5421_write_unlocked(indio_dev, reg, val);
- mutex_unlock(&indio_dev->mlock);
+ mutex_unlock(&st->lock);
return ret;
}
@@ -166,7 +169,7 @@ static int ad5421_read(struct iio_dev *indio_dev, unsigned int reg)
},
};
- mutex_lock(&indio_dev->mlock);
+ mutex_lock(&st->lock);
st->data[0].d32 = cpu_to_be32((1 << 23) | (reg << 16));
@@ -174,7 +177,7 @@ static int ad5421_read(struct iio_dev *indio_dev, unsigned int reg)
if (ret >= 0)
ret = be32_to_cpu(st->data[1].d32) & 0xffff;
- mutex_unlock(&indio_dev->mlock);
+ mutex_unlock(&st->lock);
return ret;
}
@@ -185,14 +188,14 @@ static int ad5421_update_ctrl(struct iio_dev *indio_dev, unsigned int set,
struct ad5421_state *st = iio_priv(indio_dev);
unsigned int ret;
- mutex_lock(&indio_dev->mlock);
+ mutex_lock(&st->lock);
st->ctrl &= ~clr;
st->ctrl |= set;
ret = ad5421_write_unlocked(indio_dev, AD5421_REG_CTRL, st->ctrl);
- mutex_unlock(&indio_dev->mlock);
+ mutex_unlock(&st->lock);
return ret;
}
@@ -400,12 +403,12 @@ static int ad5421_write_event_config(struct iio_dev *indio_dev,
return -EINVAL;
}
- mutex_lock(&indio_dev->mlock);
+ mutex_lock(&st->lock);
if (state)
st->fault_mask |= mask;
else
st->fault_mask &= ~mask;
- mutex_unlock(&indio_dev->mlock);
+ mutex_unlock(&st->lock);
return 0;
}
@@ -491,6 +494,8 @@ static int ad5421_probe(struct spi_device *spi)
indio_dev->channels = ad5421_channels;
indio_dev->num_channels = ARRAY_SIZE(ad5421_channels);
+ mutex_init(&st->lock);
+
st->ctrl = AD5421_CTRL_WATCHDOG_DISABLE |
AD5421_CTRL_AUTO_FAULT_READBACK;
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] iio: dac: ad5421: Replace indio_dev->mlock with own device lock
2020-05-14 9:17 [PATCH] iio: dac: ad5421: Replace indio_dev->mlock with own device lock Sergiu Cuciurean
@ 2020-05-16 15:27 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2020-05-16 15:27 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:17:53 +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/ad5421.c | 21 +++++++++++++--------
> 1 file changed, 13 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/iio/dac/ad5421.c b/drivers/iio/dac/ad5421.c
> index 63063e85cd0a..fec27764cea8 100644
> --- a/drivers/iio/dac/ad5421.c
> +++ b/drivers/iio/dac/ad5421.c
> @@ -62,12 +62,14 @@
> * @current_range: current range which the device is configured for
> * @data: spi transfer buffers
> * @fault_mask: software masking of events
> + * @lock lock to protect the data buffer during SPI ops
> */
> struct ad5421_state {
> struct spi_device *spi;
> unsigned int ctrl;
> enum ad5421_current_range current_range;
> unsigned int fault_mask;
> + struct mutex lock;
>
> /*
> * DMA (thus cache coherency maintenance) requires the
> @@ -142,11 +144,12 @@ static int ad5421_write_unlocked(struct iio_dev *indio_dev,
> static int ad5421_write(struct iio_dev *indio_dev, unsigned int reg,
> unsigned int val)
> {
> + struct ad5421_state *st = iio_priv(indio_dev);
> int ret;
>
> - mutex_lock(&indio_dev->mlock);
> + mutex_lock(&st->lock);
> ret = ad5421_write_unlocked(indio_dev, reg, val);
> - mutex_unlock(&indio_dev->mlock);
> + mutex_unlock(&st->lock);
>
> return ret;
> }
> @@ -166,7 +169,7 @@ static int ad5421_read(struct iio_dev *indio_dev, unsigned int reg)
> },
> };
>
> - mutex_lock(&indio_dev->mlock);
> + mutex_lock(&st->lock);
>
> st->data[0].d32 = cpu_to_be32((1 << 23) | (reg << 16));
>
> @@ -174,7 +177,7 @@ static int ad5421_read(struct iio_dev *indio_dev, unsigned int reg)
> if (ret >= 0)
> ret = be32_to_cpu(st->data[1].d32) & 0xffff;
>
> - mutex_unlock(&indio_dev->mlock);
> + mutex_unlock(&st->lock);
>
> return ret;
> }
> @@ -185,14 +188,14 @@ static int ad5421_update_ctrl(struct iio_dev *indio_dev, unsigned int set,
> struct ad5421_state *st = iio_priv(indio_dev);
> unsigned int ret;
>
> - mutex_lock(&indio_dev->mlock);
> + mutex_lock(&st->lock);
>
> st->ctrl &= ~clr;
> st->ctrl |= set;
>
> ret = ad5421_write_unlocked(indio_dev, AD5421_REG_CTRL, st->ctrl);
>
> - mutex_unlock(&indio_dev->mlock);
> + mutex_unlock(&st->lock);
>
> return ret;
> }
> @@ -400,12 +403,12 @@ static int ad5421_write_event_config(struct iio_dev *indio_dev,
> return -EINVAL;
> }
>
> - mutex_lock(&indio_dev->mlock);
> + mutex_lock(&st->lock);
> if (state)
> st->fault_mask |= mask;
> else
> st->fault_mask &= ~mask;
> - mutex_unlock(&indio_dev->mlock);
> + mutex_unlock(&st->lock);
>
> return 0;
> }
> @@ -491,6 +494,8 @@ static int ad5421_probe(struct spi_device *spi)
> indio_dev->channels = ad5421_channels;
> indio_dev->num_channels = ARRAY_SIZE(ad5421_channels);
>
> + mutex_init(&st->lock);
> +
> st->ctrl = AD5421_CTRL_WATCHDOG_DISABLE |
> AD5421_CTRL_AUTO_FAULT_READBACK;
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-05-16 15:27 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:17 [PATCH] iio: dac: ad5421: Replace indio_dev->mlock with own device lock Sergiu Cuciurean
2020-05-16 15:27 ` Jonathan Cameron
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.