* [PATCH] staging: iio: adc: Replace mlock with driver private lock
@ 2017-03-20 14:12 Arushi Singhal
2017-03-22 20:40 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Arushi Singhal @ 2017-03-20 14:12 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, lars
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>
---
drivers/staging/iio/adc/ad7606.c | 8 ++++----
drivers/staging/iio/adc/ad7606.h | 2 ++
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
index 9dbfa64b1e53..9f529b34e018 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:
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] 3+ messages in thread* Re: [PATCH] staging: iio: adc: Replace mlock with driver private lock
2017-03-20 14:12 [PATCH] staging: iio: adc: Replace mlock with driver private lock Arushi Singhal
@ 2017-03-22 20:40 ` Jonathan Cameron
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2017-03-22 20:40 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 14:12, 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>
mutex_init?
This partly came from the fact Alison missed it in her example
patch (and I didn't notice!), but all mutexes need to be initialized
before use. It's an interesting diversion to follow what that actually
does... There is more to a mutex than you might expect!
Jonathan
> ---
> drivers/staging/iio/adc/ad7606.c | 8 ++++----
> drivers/staging/iio/adc/ad7606.h | 2 ++
> 2 files changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
> index 9dbfa64b1e53..9f529b34e018 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:
> 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;
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] staging: iio: adc: Replace mlock with driver private lock
@ 2017-03-12 20:45 Gargi Sharma
0 siblings, 0 replies; 3+ messages in thread
From: Gargi Sharma @ 2017-03-12 20:45 UTC (permalink / raw)
To: outreachy-kernel
Cc: lars, Michael.Hennerich, jic23, knaack.h, pmeerw, linux-iio,
Gargi Sharma
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.
This was done using Coccinelle Script.
@r1@
identifier xxx_state;
@@
struct xxx_state {
...
+ struct mutex lock; /* protect sensor state */
};
@r2@
expression e;
@@
- mutex_lock(e);
+ mutex_lock(&st->lock);
@r3@
expression e;
@@
- mutex_unlock(e);
+ mutex_unlock(&st->lock);
Signed-off-by: Gargi Sharma <gs051095@gmail.com>
---
drivers/staging/iio/adc/ad7280a.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c
index ee679ac..27a3ce3 100644
--- a/drivers/staging/iio/adc/ad7280a.c
+++ b/drivers/staging/iio/adc/ad7280a.c
@@ -136,6 +136,7 @@ struct ad7280_state {
unsigned char cb_mask[AD7280A_MAX_CHAIN];
__be32 buf[2] ____cacheline_aligned;
+ struct mutex lock; /* protect sensor state */
};
static void ad7280_crc8_build_table(unsigned char *crc_tab)
@@ -410,7 +411,7 @@ static ssize_t ad7280_store_balance_sw(struct device *dev,
devaddr = this_attr->address >> 8;
ch = this_attr->address & 0xFF;
- mutex_lock(&indio_dev->mlock);
+ mutex_lock(&st->lock);
if (readin)
st->cb_mask[devaddr] |= 1 << (ch + 2);
else
@@ -418,7 +419,7 @@ static ssize_t ad7280_store_balance_sw(struct device *dev,
ret = ad7280_write(st, devaddr, AD7280A_CELL_BALANCE,
0, st->cb_mask[devaddr]);
- mutex_unlock(&indio_dev->mlock);
+ mutex_unlock(&st->lock);
return ret ? ret : len;
}
@@ -433,10 +434,10 @@ static ssize_t ad7280_show_balance_timer(struct device *dev,
int ret;
unsigned int msecs;
- mutex_lock(&indio_dev->mlock);
+ mutex_lock(&st->lock);
ret = ad7280_read(st, this_attr->address >> 8,
this_attr->address & 0xFF);
- mutex_unlock(&indio_dev->mlock);
+ mutex_unlock(&st->lock);
if (ret < 0)
return ret;
@@ -466,11 +467,11 @@ static ssize_t ad7280_store_balance_timer(struct device *dev,
if (val > 31)
return -EINVAL;
- mutex_lock(&indio_dev->mlock);
+ mutex_lock(&st->lock);
ret = ad7280_write(st, this_attr->address >> 8,
this_attr->address & 0xFF,
0, (val & 0x1F) << 3);
- mutex_unlock(&indio_dev->mlock);
+ mutex_unlock(&st->lock);
return ret ? ret : len;
}
@@ -655,7 +656,7 @@ static ssize_t ad7280_write_channel_config(struct device *dev,
val = clamp(val, 0L, 0xFFL);
- mutex_lock(&indio_dev->mlock);
+ mutex_lock(&st->lock);
switch ((u32)this_attr->address) {
case AD7280A_CELL_OVERVOLTAGE:
st->cell_threshhigh = val;
@@ -674,7 +675,7 @@ static ssize_t ad7280_write_channel_config(struct device *dev,
ret = ad7280_write(st, AD7280A_DEVADDR_MASTER,
this_attr->address, 1, val);
- mutex_unlock(&indio_dev->mlock);
+ mutex_unlock(&st->lock);
return ret ? ret : len;
}
@@ -792,13 +793,13 @@ static int ad7280_read_raw(struct iio_dev *indio_dev,
switch (m) {
case IIO_CHAN_INFO_RAW:
- mutex_lock(&indio_dev->mlock);
+ mutex_lock(&st->lock);
if (chan->address == AD7280A_ALL_CELLS)
ret = ad7280_read_all_channels(st, st->scan_cnt, NULL);
else
ret = ad7280_read_channel(st, chan->address >> 8,
chan->address & 0xFF);
- mutex_unlock(&indio_dev->mlock);
+ mutex_unlock(&st->lock);
if (ret < 0)
return ret;
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-03-22 20:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-20 14:12 [PATCH] staging: iio: adc: Replace mlock with driver private lock Arushi Singhal
2017-03-22 20:40 ` Jonathan Cameron
-- strict thread matches above, loose matches on Subject: below --
2017-03-12 20:45 Gargi Sharma
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).