All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: iio: adc: Replace mlock with driver private lock
@ 2017-03-12 20:45 Gargi Sharma
  2017-03-12 20:56 ` [Outreachy kernel] " Julia Lawall
  0 siblings, 1 reply; 22+ 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] 22+ messages in thread

end of thread, other threads:[~2017-03-16 17:45 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-12 20:45 [PATCH] staging: iio: adc: Replace mlock with driver private lock Gargi Sharma
2017-03-12 20:56 ` [Outreachy kernel] " Julia Lawall
2017-03-12 21:33   ` Gargi Sharma
2017-03-12 21:37     ` Julia Lawall
2017-03-12 22:13       ` Alison Schofield
2017-03-12 22:27         ` Julia Lawall
2017-03-13  8:41           ` Gargi Sharma
2017-03-15  9:44             ` Julia Lawall
2017-03-13  8:40         ` Gargi Sharma
2017-03-13 20:40           ` Julia Lawall
2017-03-13 20:50             ` Jonathan Cameron
2017-03-13 21:09               ` Julia Lawall
2017-03-13 20:51           ` Jonathan Cameron
2017-03-13 20:54             ` Lars-Peter Clausen
2017-03-13 21:25               ` Jonathan Cameron
2017-03-14 17:36               ` Gargi Sharma
2017-03-14 17:36                 ` Gargi Sharma
2017-03-14 22:44                 ` Jonathan Cameron
2017-03-14 22:44                   ` Jonathan Cameron
2017-03-15 18:15                   ` Gargi Sharma
2017-03-16 17:41                     ` Alison Schofield
2017-03-16 17:45                       ` Alison Schofield

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.