Skip to contentSkip to conversation

staging: iio: ad9834: Use private driver lock instead of mlock

PATCH Superseded sayli karnik 3 participants 4 messages Mar 12, 2017

Subsystems (4)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: iio: ad9834: Use private driver lock instead of mlock

iio_dev->mlock should be used by the IIO core only for protecting device operating mode changes. ie. Changes between INDIO_DIRECT_MODE, INDIO_BUFFER_* modes.
Replace mlock with a lock in the device's global data to protect hardware state changes.

---
 drivers/staging/iio/frequency/ad9834.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/staging/iio/frequency/ad9834.c +6 -4
index f92ff7f..4259474 100644
@@ -63,6 +63,7 @@
  * @msg:		default spi message
  * @freq_xfer:		tuning word spi transfer
  * @freq_msg:		tuning word spi message
+ * @lock:		protect sensor state
  * @data:		spi transmit buffer
  * @freq_data:		tuning word spi transmit buffer
  */
@@ -77,6 +78,7 @@ struct ad9834_state {
 	struct spi_message		msg;
 	struct spi_transfer		freq_xfer[2];
 	struct spi_message		freq_msg;
+	struct mutex			lock;	/* protect sensor state */
 
 	/*
 	 * DMA (thus cache coherency maintenance) requires the
@@ -149,7 +151,7 @@ static ssize_t ad9834_write(struct device *dev,
 	if (ret)
 		goto error_ret;
 
-	mutex_lock(&indio_dev->mlock);
+	mutex_lock(&st->lock);
 	switch ((u32)this_attr->address) {
 	case AD9834_REG_FREQ0:
 	case AD9834_REG_FREQ1:
@@ -207,7 +209,7 @@ static ssize_t ad9834_write(struct device *dev,
 	default:
 		ret = -ENODEV;
 	}
-	mutex_unlock(&indio_dev->mlock);
+	mutex_unlock(&st->lock);
 
 error_ret:
 	return ret ? ret : len;
@@ -224,7 +226,7 @@ static ssize_t ad9834_store_wavetype(struct device *dev,
 	int ret = 0;
 	bool is_ad9833_7 = (st->devid == ID_AD9833) || (st->devid == ID_AD9837);
 
-	mutex_lock(&indio_dev->mlock);
+	mutex_lock(&st->lock);
 
 	switch ((u32)this_attr->address) {
 	case 0:
@@ -267,7 +269,7 @@ static ssize_t ad9834_store_wavetype(struct device *dev,
 		st->data = cpu_to_be16(AD9834_REG_CMD | st->control);
 		ret = spi_sync(st->spi, &st->msg);
 	}
-	mutex_unlock(&indio_dev->mlock);
+	mutex_lock(&st->lock);
 
 	return ret ? ret : len;
 }
Signature · 1 line
2.7.4
#1 lore raw
Quoted 5 lines · sayli karnik

iio_dev->mlock should be used by the IIO core only for protecting device operating mode changes. ie. Changes between INDIO_DIRECT_MODE, INDIO_BUFFER_* modes.
Replace mlock with a lock in the device's global data to protect hardware state changes.

Hi Sayli,
Thanks for the patch! Find one fix-up and one opportunity for a follow on patch embedded below.
alisons

Quoted 27 lines
---
 drivers/staging/iio/frequency/ad9834.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/staging/iio/frequency/ad9834.c +2 -0
index f92ff7f..4259474 100644
@@ -63,6 +63,7 @@
  * @msg:		default spi message
  * @freq_xfer:		tuning word spi transfer
  * @freq_msg:		tuning word spi message
+ * @lock:		protect sensor state
  * @data:		spi transmit buffer
  * @freq_data:		tuning word spi transmit buffer
  */
@@ -77,6 +78,7 @@ struct ad9834_state {
 	struct spi_message		msg;
 	struct spi_transfer		freq_xfer[2];
 	struct spi_message		freq_msg;
+	struct mutex			lock;	/* protect sensor state */
 
 	/*
 	 * DMA (thus cache coherency maintenance) requires the

drivers/staging/iio/frequency/ad9834.c static ssize_t ad9834_write(struct device *dev, · line 152

Quoted 2 lines
drivers/staging/iio/frequency/ad9834.c +0 -0
@@ -149,7 +151,7 @@ static ssize_t ad9834_write(struct device *dev,
 	if (ret)
 		goto error_ret;

Not related to your patch...the above goto error_ret seems excessived. When you look down at error_ret, it's not doing any clean up. So, perhaps we can just return right here and get rid of the goto & label?

Quoted 25 lines
drivers/staging/iio/frequency/ad9834.c +3 -3
-	mutex_lock(&indio_dev->mlock);
+	mutex_lock(&st->lock);
 	switch ((u32)this_attr->address) {
 	case AD9834_REG_FREQ0:
 	case AD9834_REG_FREQ1:
@@ -207,7 +209,7 @@ static ssize_t ad9834_write(struct device *dev,
 	default:
 		ret = -ENODEV;
 	}
-	mutex_unlock(&indio_dev->mlock);
+	mutex_unlock(&st->lock);
 
 error_ret:
 	return ret ? ret : len;
@@ -224,7 +226,7 @@ static ssize_t ad9834_store_wavetype(struct device *dev,
 	int ret = 0;
 	bool is_ad9833_7 = (st->devid == ID_AD9833) || (st->devid == ID_AD9837);
 
-	mutex_lock(&indio_dev->mlock);
+	mutex_lock(&st->lock);
 
 	switch ((u32)this_attr->address) {
 	case 0:

drivers/staging/iio/frequency/ad9834.c static ssize_t ad9834_store_wavetype(struct device *dev, · line 272

Quoted 5 lines
drivers/staging/iio/frequency/ad9834.c +1 -1
@@ -267,7 +269,7 @@ static ssize_t ad9834_store_wavetype(struct device *dev,
 		st->data = cpu_to_be16(AD9834_REG_CMD | st->control);
 		ret = spi_sync(st->spi, &st->msg);
 	}
-	mutex_unlock(&indio_dev->mlock);
+	mutex_lock(&st->lock);

Needs to be mutex_unlock()

Quoted 12 lines
drivers/staging/iio/frequency/ad9834.c +0 -0
 	return ret ? ret : len;
 }
Signature · 8 lines
2.7.4

-- 
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20170312115013.GA31878%40sayli-HP-15-Notebook-PC.
For more options, visit https://groups.google.com/d/optout.
#2 lore raw
Quoted 36 lines · Alison Schofield
Quoted 5 lines · sayli karnik

iio_dev->mlock should be used by the IIO core only for protecting device operating mode changes. ie. Changes between INDIO_DIRECT_MODE, INDIO_BUFFER_* modes.
Replace mlock with a lock in the device's global data to protect hardware state changes.

Hi Sayli,
Thanks for the patch! Find one fix-up and one opportunity for a follow on patch embedded below.
alisons

Quoted 24 lines
---
 drivers/staging/iio/frequency/ad9834.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/staging/iio/frequency/ad9834.c +2 -0
index f92ff7f..4259474 100644
@@ -63,6 +63,7 @@
  * @msg:             default spi message
  * @freq_xfer:               tuning word spi transfer
  * @freq_msg:                tuning word spi message
+ * @lock:            protect sensor state
  * @data:            spi transmit buffer
  * @freq_data:               tuning word spi transmit buffer
  */
@@ -77,6 +78,7 @@ struct ad9834_state {
      struct spi_message              msg;
      struct spi_transfer             freq_xfer[2];
      struct spi_message              freq_msg;
+     struct mutex                    lock;   /* protect sensor state */
 
Quoted 10 lines

drivers/staging/iio/frequency/ad9834.c static ssize_t ad9834_write(struct device *dev, · line 152

Quoted 5 lines
drivers/staging/iio/frequency/ad9834.c +0 -0
      /*
       * DMA (thus cache coherency maintenance) requires the
@@ -149,7 +151,7 @@ static ssize_t ad9834_write(struct device *dev,
      if (ret)
              goto error_ret;

Not related to your patch...the above goto error_ret seems excessived. When you look down at error_ret, it's not doing any clean up. So, perhaps we can just return right here and get rid of the goto & label?

Right! This has to be on top of Greg's tree and not this patch I'm assuming?

Quoted 45 lines
Quoted 25 lines
drivers/staging/iio/frequency/ad9834.c +3 -3
-     mutex_lock(&indio_dev->mlock);
+     mutex_lock(&st->lock);
      switch ((u32)this_attr->address) {
      case AD9834_REG_FREQ0:
      case AD9834_REG_FREQ1:
@@ -207,7 +209,7 @@ static ssize_t ad9834_write(struct device *dev,
      default:
              ret = -ENODEV;
      }
-     mutex_unlock(&indio_dev->mlock);
+     mutex_unlock(&st->lock);
 
 error_ret:
      return ret ? ret : len;
@@ -224,7 +226,7 @@ static ssize_t ad9834_store_wavetype(struct device *dev,
      int ret = 0;
      bool is_ad9833_7 = (st->devid == ID_AD9833) || (st->devid == ID_AD9837);
 
-     mutex_lock(&indio_dev->mlock);
+     mutex_lock(&st->lock);
 
      switch ((u32)this_attr->address) {
      case 0:

drivers/staging/iio/frequency/ad9834.c static ssize_t ad9834_store_wavetype(struct device *dev, · line 272

Quoted 5 lines
drivers/staging/iio/frequency/ad9834.c +1 -1
@@ -267,7 +269,7 @@ static ssize_t ad9834_store_wavetype(struct device *dev,
              st->data = cpu_to_be16(AD9834_REG_CMD | st->control);
              ret = spi_sync(st->spi, &st->msg);
      }
-     mutex_unlock(&indio_dev->mlock);
+     mutex_lock(&st->lock);

Needs to be mutex_unlock()

Quoted 12 lines
drivers/staging/iio/frequency/ad9834.c +0 -1
      return ret ? ret : len;
 }
--

2.7.4

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20170312115013.GA31878%40sayli-HP-15-Notebook-PC.
For more options, visit https://groups.google.com/d/optout.

#3 lore raw
Quoted 47 lines · sayli karnik
Quoted 36 lines · Alison Schofield
Quoted 5 lines · sayli karnik

iio_dev->mlock should be used by the IIO core only for protecting device operating mode changes. ie. Changes between INDIO_DIRECT_MODE, INDIO_BUFFER_* modes.
Replace mlock with a lock in the device's global data to protect hardware state changes.

Hi Sayli,
Thanks for the patch! Find one fix-up and one opportunity for a follow on patch embedded below.
alisons

Quoted 24 lines
---
 drivers/staging/iio/frequency/ad9834.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/staging/iio/frequency/ad9834.c +2 -0
index f92ff7f..4259474 100644
@@ -63,6 +63,7 @@
  * @msg:             default spi message
  * @freq_xfer:               tuning word spi transfer
  * @freq_msg:                tuning word spi message
+ * @lock:            protect sensor state
  * @data:            spi transmit buffer
  * @freq_data:               tuning word spi transmit buffer
  */
@@ -77,6 +78,7 @@ struct ad9834_state {
      struct spi_message              msg;
      struct spi_transfer             freq_xfer[2];
      struct spi_message              freq_msg;
+     struct mutex                    lock;   /* protect sensor state */
 
Quoted 10 lines

drivers/staging/iio/frequency/ad9834.c static ssize_t ad9834_write(struct device *dev, · line 152

Quoted 5 lines
drivers/staging/iio/frequency/ad9834.c +0 -0
      /*
       * DMA (thus cache coherency maintenance) requires the
@@ -149,7 +151,7 @@ static ssize_t ad9834_write(struct device *dev,
      if (ret)
              goto error_ret;

Not related to your patch...the above goto error_ret seems excessived. When you look down at error_ret, it's not doing any clean up. So, perhaps we can just return right here and get rid of the goto & label?

Quoted 1 line

Right! This has to be on top of Greg's tree and not this patch I'm assuming?

You need to make a series if you want to send two patches on the same file.

julia

Quoted 53 lines
Quoted 22 lines
Quoted 22 lines
drivers/staging/iio/frequency/ad9834.c +3 -3
-     mutex_lock(&indio_dev->mlock);
+     mutex_lock(&st->lock);
      switch ((u32)this_attr->address) {
      case AD9834_REG_FREQ0:
      case AD9834_REG_FREQ1:
@@ -207,7 +209,7 @@ static ssize_t ad9834_write(struct device *dev,
      default:
              ret = -ENODEV;
      }
-     mutex_unlock(&indio_dev->mlock);
+     mutex_unlock(&st->lock);
 
 error_ret:
      return ret ? ret : len;
@@ -224,7 +226,7 @@ static ssize_t ad9834_store_wavetype(struct device *dev,
      int ret = 0;
      bool is_ad9833_7 = (st->devid == ID_AD9833) || (st->devid == ID_AD9837);
 
-     mutex_lock(&indio_dev->mlock);
+     mutex_lock(&st->lock);
 
Quoted 23 lines

drivers/staging/iio/frequency/ad9834.c static ssize_t ad9834_store_wavetype(struct device *dev, · line 272

Quoted 8 lines
drivers/staging/iio/frequency/ad9834.c +1 -1
      switch ((u32)this_attr->address) {
      case 0:
@@ -267,7 +269,7 @@ static ssize_t ad9834_store_wavetype(struct device *dev,
              st->data = cpu_to_be16(AD9834_REG_CMD | st->control);
              ret = spi_sync(st->spi, &st->msg);
      }
-     mutex_unlock(&indio_dev->mlock);
+     mutex_lock(&st->lock);

Needs to be mutex_unlock()

Quoted 12 lines
drivers/staging/iio/frequency/ad9834.c +0 -1
      return ret ? ret : len;
 }
--

2.7.4

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20170312115013.GA31878%40sayli-HP-15-Notebook-PC.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/CAKG5xWhoYww_U9zNv%3D9EiAOya3R0C6Aafm3BUAfzdCXSYk4y%2BA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.