* [PATCH v3] staging: ad7606: Replace mlock with driver private lock
@ 2017-03-20 18:56 Arushi Singhal
2017-03-20 19:33 ` Lars-Peter Clausen
0 siblings, 1 reply; 4+ messages in thread
From: Arushi Singhal @ 2017-03-20 18:56 UTC (permalink / raw)
To: lars
Cc: Michael Hennerich, Jonathan Cameron, Hartmut Knaack,
Peter Meerwald-Stadler, Greg Kroah-Hartman, linux-iio, devel,
linux-kernel, outreachy-kernel
The IIO subsystem is redefining iio_dev->mlock to be used by
the IIO core only for protecting device operating mode changes.
ie. Changes between INDIO_DIRECT_MODE, INDIO_BUFFER_* modes.
In this driver, mlock was being used to protect hardware state
changes. Replace it with a lock in the devices global data.
Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com>
---
changes in v3
- Add mutex_init.
drivers/staging/iio/adc/ad7606.c | 9 +++++----
drivers/staging/iio/adc/ad7606.h | 2 ++
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
index 9dbfa64b1e53..18f5f139117e 100644
--- a/drivers/staging/iio/adc/ad7606.c
+++ b/drivers/staging/iio/adc/ad7606.c
@@ -208,7 +208,7 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,
switch (mask) {
case IIO_CHAN_INFO_SCALE:
ret = -EINVAL;
- mutex_lock(&indio_dev->mlock);
+ mutex_lock(&st->lock);
for (i = 0; i < ARRAY_SIZE(scale_avail); i++)
if (val2 == scale_avail[i][1]) {
gpiod_set_value(st->gpio_range, i);
@@ -217,7 +217,7 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,
ret = 0;
break;
}
- mutex_unlock(&indio_dev->mlock);
+ mutex_unlock(&st->lock);
return ret;
case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
@@ -231,11 +231,11 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,
values[1] = (ret >> 1) & 1;
values[2] = (ret >> 2) & 1;
- mutex_lock(&indio_dev->mlock);
+ mutex_lock(&st->lock);
gpiod_set_array_value(ARRAY_SIZE(values), st->gpio_os->desc,
values);
st->oversampling = val;
- mutex_unlock(&indio_dev->mlock);
+ mutex_unlock(&st->lock);
return 0;
default:
@@ -413,6 +413,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
st = iio_priv(indio_dev);
st->dev = dev;
+ mutex_init(&st->lock);
st->bops = bops;
st->base_address = base_address;
/* tied to logic low, analog input range is +/- 5V */
diff --git a/drivers/staging/iio/adc/ad7606.h b/drivers/staging/iio/adc/ad7606.h
index 746f9553d2ba..5d59bdd78727 100644
--- a/drivers/staging/iio/adc/ad7606.h
+++ b/drivers/staging/iio/adc/ad7606.h
@@ -14,6 +14,7 @@
* @name: identification string for chip
* @channels: channel specification
* @num_channels: number of channels
+ * @lock protect sensor state
*/
struct ad7606_chip_info {
@@ -37,6 +38,7 @@ struct ad7606_state {
bool done;
void __iomem *base_address;
+ struct mutex lock; /* protect sensor state */
struct gpio_desc *gpio_convst;
struct gpio_desc *gpio_reset;
struct gpio_desc *gpio_range;
--
2.11.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3] staging: ad7606: Replace mlock with driver private lock
2017-03-20 18:56 [PATCH v3] staging: ad7606: Replace mlock with driver private lock Arushi Singhal
@ 2017-03-20 19:33 ` Lars-Peter Clausen
0 siblings, 0 replies; 4+ messages in thread
From: Lars-Peter Clausen @ 2017-03-20 19:33 UTC (permalink / raw)
To: Arushi Singhal
Cc: Michael Hennerich, Jonathan Cameron, Hartmut Knaack,
Peter Meerwald-Stadler, Greg Kroah-Hartman, linux-iio, devel,
linux-kernel, outreachy-kernel
On 03/20/2017 07:56 PM, Arushi Singhal wrote:
[...]
> @@ -413,6 +413,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
> st = iio_priv(indio_dev);
>
> st->dev = dev;
> + mutex_init(&st->lock);
This is nitpicking, but putting this in the middle of the assignments has a
bit of a weired flow it. Either put it above or below the assignments.
> st->bops = bops;
> st->base_address = base_address;
> /* tied to logic low, analog input range is +/- 5V */
> diff --git a/drivers/staging/iio/adc/ad7606.h b/drivers/staging/iio/adc/ad7606.h
> index 746f9553d2ba..5d59bdd78727 100644
> --- a/drivers/staging/iio/adc/ad7606.h
> +++ b/drivers/staging/iio/adc/ad7606.h
> @@ -14,6 +14,7 @@
> * @name: identification string for chip
> * @channels: channel specification
> * @num_channels: number of channels
> + * @lock protect sensor state
This documentation is for struct ad7607_chip_info, but you are adding the
field to struct ad7606_state.
> */
>
> struct ad7606_chip_info {
> @@ -37,6 +38,7 @@ struct ad7606_state {
> bool done;
> void __iomem *base_address;
>
> + struct mutex lock; /* protect sensor state */
> struct gpio_desc *gpio_convst;
> struct gpio_desc *gpio_reset;
> struct gpio_desc *gpio_range;
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] staging: ad7606: Replace mlock with driver private lock
2017-03-20 19:51 Arushi Singhal
@ 2017-03-22 20:28 ` Jonathan Cameron
0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2017-03-22 20:28 UTC (permalink / raw)
To: Arushi Singhal, lars
Cc: Michael Hennerich, Hartmut Knaack, Peter Meerwald-Stadler,
Greg Kroah-Hartman, linux-iio, devel, linux-kernel,
outreachy-kernel
On 20/03/17 19:51, Arushi Singhal wrote:
> The IIO subsystem is redefining iio_dev->mlock to be used by
> the IIO core only for protecting device operating mode changes.
> ie. Changes between INDIO_DIRECT_MODE, INDIO_BUFFER_* modes.
>
> In this driver, mlock was being used to protect hardware state
> changes. Replace it with a lock in the devices global data.
>
> Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com>
Nice patch.
Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.
Thanks,
Jonathan
> ---
> changes in v3
> - Add mutex_init.
> - correct the Documentation.
>
> drivers/staging/iio/adc/ad7606.c | 9 +++++----
> drivers/staging/iio/adc/ad7606.h | 3 +++
> 2 files changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
> index 9dbfa64b1e53..18f5f139117e 100644
> --- a/drivers/staging/iio/adc/ad7606.c
> +++ b/drivers/staging/iio/adc/ad7606.c
> @@ -208,7 +208,7 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,
> switch (mask) {
> case IIO_CHAN_INFO_SCALE:
> ret = -EINVAL;
> - mutex_lock(&indio_dev->mlock);
> + mutex_lock(&st->lock);
> for (i = 0; i < ARRAY_SIZE(scale_avail); i++)
> if (val2 == scale_avail[i][1]) {
> gpiod_set_value(st->gpio_range, i);
> @@ -217,7 +217,7 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,
> ret = 0;
> break;
> }
> - mutex_unlock(&indio_dev->mlock);
> + mutex_unlock(&st->lock);
>
> return ret;
> case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> @@ -231,11 +231,11 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,
> values[1] = (ret >> 1) & 1;
> values[2] = (ret >> 2) & 1;
>
> - mutex_lock(&indio_dev->mlock);
> + mutex_lock(&st->lock);
> gpiod_set_array_value(ARRAY_SIZE(values), st->gpio_os->desc,
> values);
> st->oversampling = val;
> - mutex_unlock(&indio_dev->mlock);
> + mutex_unlock(&st->lock);
>
> return 0;
> default:
> @@ -413,6 +413,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
> st = iio_priv(indio_dev);
>
> st->dev = dev;
> + mutex_init(&st->lock);
> st->bops = bops;
> st->base_address = base_address;
> /* tied to logic low, analog input range is +/- 5V */
> diff --git a/drivers/staging/iio/adc/ad7606.h b/drivers/staging/iio/adc/ad7606.h
> index 746f9553d2ba..acaed8d5379c 100644
> --- a/drivers/staging/iio/adc/ad7606.h
> +++ b/drivers/staging/iio/adc/ad7606.h
> @@ -14,6 +14,7 @@
> * @name: identification string for chip
> * @channels: channel specification
> * @num_channels: number of channels
> + * @lock protect sensor state
> */
>
> struct ad7606_chip_info {
> @@ -23,6 +24,7 @@ struct ad7606_chip_info {
>
> /**
> * struct ad7606_state - driver instance specific data
> + * @lock protect sensor state
> */
>
> struct ad7606_state {
> @@ -37,6 +39,7 @@ struct ad7606_state {
> bool done;
> void __iomem *base_address;
>
> + struct mutex lock; /* protect sensor state */
> struct gpio_desc *gpio_convst;
> struct gpio_desc *gpio_reset;
> struct gpio_desc *gpio_range;
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v3] staging: ad7606: Replace mlock with driver private lock
@ 2017-03-20 19:51 Arushi Singhal
2017-03-22 20:28 ` Jonathan Cameron
0 siblings, 1 reply; 4+ messages in thread
From: Arushi Singhal @ 2017-03-20 19:51 UTC (permalink / raw)
To: lars
Cc: Michael Hennerich, Jonathan Cameron, Hartmut Knaack,
Peter Meerwald-Stadler, Greg Kroah-Hartman, linux-iio, devel,
linux-kernel, outreachy-kernel
The IIO subsystem is redefining iio_dev->mlock to be used by
the IIO core only for protecting device operating mode changes.
ie. Changes between INDIO_DIRECT_MODE, INDIO_BUFFER_* modes.
In this driver, mlock was being used to protect hardware state
changes. Replace it with a lock in the devices global data.
Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com>
---
changes in v3
- Add mutex_init.
- correct the Documentation.
drivers/staging/iio/adc/ad7606.c | 9 +++++----
drivers/staging/iio/adc/ad7606.h | 3 +++
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
index 9dbfa64b1e53..18f5f139117e 100644
--- a/drivers/staging/iio/adc/ad7606.c
+++ b/drivers/staging/iio/adc/ad7606.c
@@ -208,7 +208,7 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,
switch (mask) {
case IIO_CHAN_INFO_SCALE:
ret = -EINVAL;
- mutex_lock(&indio_dev->mlock);
+ mutex_lock(&st->lock);
for (i = 0; i < ARRAY_SIZE(scale_avail); i++)
if (val2 == scale_avail[i][1]) {
gpiod_set_value(st->gpio_range, i);
@@ -217,7 +217,7 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,
ret = 0;
break;
}
- mutex_unlock(&indio_dev->mlock);
+ mutex_unlock(&st->lock);
return ret;
case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
@@ -231,11 +231,11 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,
values[1] = (ret >> 1) & 1;
values[2] = (ret >> 2) & 1;
- mutex_lock(&indio_dev->mlock);
+ mutex_lock(&st->lock);
gpiod_set_array_value(ARRAY_SIZE(values), st->gpio_os->desc,
values);
st->oversampling = val;
- mutex_unlock(&indio_dev->mlock);
+ mutex_unlock(&st->lock);
return 0;
default:
@@ -413,6 +413,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
st = iio_priv(indio_dev);
st->dev = dev;
+ mutex_init(&st->lock);
st->bops = bops;
st->base_address = base_address;
/* tied to logic low, analog input range is +/- 5V */
diff --git a/drivers/staging/iio/adc/ad7606.h b/drivers/staging/iio/adc/ad7606.h
index 746f9553d2ba..acaed8d5379c 100644
--- a/drivers/staging/iio/adc/ad7606.h
+++ b/drivers/staging/iio/adc/ad7606.h
@@ -14,6 +14,7 @@
* @name: identification string for chip
* @channels: channel specification
* @num_channels: number of channels
+ * @lock protect sensor state
*/
struct ad7606_chip_info {
@@ -23,6 +24,7 @@ struct ad7606_chip_info {
/**
* struct ad7606_state - driver instance specific data
+ * @lock protect sensor state
*/
struct ad7606_state {
@@ -37,6 +39,7 @@ struct ad7606_state {
bool done;
void __iomem *base_address;
+ struct mutex lock; /* protect sensor state */
struct gpio_desc *gpio_convst;
struct gpio_desc *gpio_reset;
struct gpio_desc *gpio_range;
--
2.11.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-03-22 20:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-20 18:56 [PATCH v3] staging: ad7606: Replace mlock with driver private lock Arushi Singhal
2017-03-20 19:33 ` Lars-Peter Clausen
2017-03-20 19:51 Arushi Singhal
2017-03-22 20:28 ` 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).