All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Replace mlock with private lock and improve code flow
@ 2017-03-12 22:15 sayli karnik
  2017-03-12 22:17 ` [PATCH v2 1/2] staging: iio: ad9834: Use private driver lock instead of mlock sayli karnik
  2017-03-12 22:19 ` [PATCH v2 2/2] staging: iio: ad9834: Remove unnecessary goto label and compress return logic sayli karnik
  0 siblings, 2 replies; 6+ messages in thread
From: sayli karnik @ 2017-03-12 22:15 UTC (permalink / raw)
  To: outreachy-kernel
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	Hartmut Knaack, Peter Meerwald-Stadler, Greg Kroah-Hartman,
	linux-iio

The patch series replaces mlock with a private lock for driver ad9834 and
improves code flow by eliminating excessive goto.

sayli karnik (2):
  staging: iio: ad9834: Use private driver lock instead of mlock
  staging: iio: ad9834: Remove unnecessary goto label and compress
    return logic

 drivers/staging/iio/frequency/ad9834.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/2] staging: iio: ad9834: Use private driver lock instead of mlock
  2017-03-12 22:15 [PATCH v2 0/2] Replace mlock with private lock and improve code flow sayli karnik
@ 2017-03-12 22:17 ` sayli karnik
  2017-03-12 22:19 ` [PATCH v2 2/2] staging: iio: ad9834: Remove unnecessary goto label and compress return logic sayli karnik
  1 sibling, 0 replies; 6+ messages in thread
From: sayli karnik @ 2017-03-12 22:17 UTC (permalink / raw)
  To: outreachy-kernel
  Cc: linux-iio, Lars-Peter Clausen, Michael Hennerich,
	Jonathan Cameron, Hartmut Knaack, Peter Meerwald-Stadler,
	Greg Kroah-Hartman

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.

Signed-off-by: sayli karnik <karniksayli1995@gmail.com>
---
v2:
Fixed mistake by changing mutex_lock() to mutex_unlock()

 drivers/staging/iio/frequency/ad9834.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c
index f92ff7f..60461a6 100644
--- a/drivers/staging/iio/frequency/ad9834.c
+++ b/drivers/staging/iio/frequency/ad9834.c
@@ -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_unlock(&st->lock);
 
 	return ret ? ret : len;
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/2] staging: iio: ad9834: Remove unnecessary goto label and compress return logic
  2017-03-12 22:15 [PATCH v2 0/2] Replace mlock with private lock and improve code flow sayli karnik
  2017-03-12 22:17 ` [PATCH v2 1/2] staging: iio: ad9834: Use private driver lock instead of mlock sayli karnik
@ 2017-03-12 22:19 ` sayli karnik
  2017-03-12 22:27   ` [Outreachy kernel] " Alison Schofield
  2017-03-12 22:28   ` Julia Lawall
  1 sibling, 2 replies; 6+ messages in thread
From: sayli karnik @ 2017-03-12 22:19 UTC (permalink / raw)
  To: outreachy-kernel
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	Hartmut Knaack, Peter Meerwald-Stadler, Greg Kroah-Hartman,
	linux-iio

The patch removes excessive goto label and compresses return logic.

Signed-off-by: sayli karnik <karniksayli1995@gmail.com>
---
 drivers/staging/iio/frequency/ad9834.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c
index 60461a6..18f3e8f 100644
--- a/drivers/staging/iio/frequency/ad9834.c
+++ b/drivers/staging/iio/frequency/ad9834.c
@@ -147,9 +147,8 @@ static ssize_t ad9834_write(struct device *dev,
 	int ret;
 	unsigned long val;
 
-	ret = kstrtoul(buf, 10, &val);
-	if (ret)
-		goto error_ret;
+	if (kstrtoul(buf, 10, &val))
+		return kstrtoul(buf, 10, &val);
 
 	mutex_lock(&st->lock);
 	switch ((u32)this_attr->address) {
@@ -211,7 +210,6 @@ static ssize_t ad9834_write(struct device *dev,
 	}
 	mutex_unlock(&st->lock);
 
-error_ret:
 	return ret ? ret : len;
 }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Outreachy kernel] [PATCH v2 2/2] staging: iio: ad9834: Remove unnecessary goto label and compress return logic
  2017-03-12 22:19 ` [PATCH v2 2/2] staging: iio: ad9834: Remove unnecessary goto label and compress return logic sayli karnik
@ 2017-03-12 22:27   ` Alison Schofield
  2017-03-13  7:17     ` sayli karnik
  2017-03-12 22:28   ` Julia Lawall
  1 sibling, 1 reply; 6+ messages in thread
From: Alison Schofield @ 2017-03-12 22:27 UTC (permalink / raw)
  To: sayli karnik
  Cc: outreachy-kernel, Lars-Peter Clausen, Michael Hennerich,
	Jonathan Cameron, Hartmut Knaack, Peter Meerwald-Stadler,
	Greg Kroah-Hartman, linux-iio

On Mon, Mar 13, 2017 at 03:49:13AM +0530, sayli karnik wrote:
> The patch removes excessive goto label and compresses return logic.
> 
> Signed-off-by: sayli karnik <karniksayli1995@gmail.com>
> ---
>  drivers/staging/iio/frequency/ad9834.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c
> index 60461a6..18f3e8f 100644
> --- a/drivers/staging/iio/frequency/ad9834.c
> +++ b/drivers/staging/iio/frequency/ad9834.c
> @@ -147,9 +147,8 @@ static ssize_t ad9834_write(struct device *dev,
>  	int ret;
>  	unsigned long val;
>  
> -	ret = kstrtoul(buf, 10, &val);
> -	if (ret)
> -		goto error_ret;
> +	if (kstrtoul(buf, 10, &val))
> +		return kstrtoul(buf, 10, &val);

Will a smaller change suffice?

ret = kstrtoul(buf, 10, &val);
if (ret)
-	goto error_ret;
+	return ret;

alisons

>  
>  	mutex_lock(&st->lock);
>  	switch ((u32)this_attr->address) {
> @@ -211,7 +210,6 @@ static ssize_t ad9834_write(struct device *dev,
>  	}
>  	mutex_unlock(&st->lock);
>  
> -error_ret:
>  	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 outreachy-kernel+unsubscribe@googlegroups.com.
> To post to this group, send email to outreachy-kernel@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/59ddccc600cfd1594dcb4dadb44b80328fc06008.1489356140.git.karniksayli1995%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Outreachy kernel] [PATCH v2 2/2] staging: iio: ad9834: Remove unnecessary goto label and compress return logic
  2017-03-12 22:19 ` [PATCH v2 2/2] staging: iio: ad9834: Remove unnecessary goto label and compress return logic sayli karnik
  2017-03-12 22:27   ` [Outreachy kernel] " Alison Schofield
@ 2017-03-12 22:28   ` Julia Lawall
  1 sibling, 0 replies; 6+ messages in thread
From: Julia Lawall @ 2017-03-12 22:28 UTC (permalink / raw)
  To: sayli karnik
  Cc: outreachy-kernel, Lars-Peter Clausen, Michael Hennerich,
	Jonathan Cameron, Hartmut Knaack, Peter Meerwald-Stadler,
	Greg Kroah-Hartman, linux-iio



On Mon, 13 Mar 2017, sayli karnik wrote:

> The patch removes excessive goto label and compresses return logic.
>
> Signed-off-by: sayli karnik <karniksayli1995@gmail.com>
> ---
>  drivers/staging/iio/frequency/ad9834.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c
> index 60461a6..18f3e8f 100644
> --- a/drivers/staging/iio/frequency/ad9834.c
> +++ b/drivers/staging/iio/frequency/ad9834.c
> @@ -147,9 +147,8 @@ static ssize_t ad9834_write(struct device *dev,
>  	int ret;
>  	unsigned long val;
>
> -	ret = kstrtoul(buf, 10, &val);
> -	if (ret)
> -		goto error_ret;
> +	if (kstrtoul(buf, 10, &val))
> +		return kstrtoul(buf, 10, &val);

Not such a good idea.  The function does some work, and there is no need
to repeat it.

julia

>
>  	mutex_lock(&st->lock);
>  	switch ((u32)this_attr->address) {
> @@ -211,7 +210,6 @@ static ssize_t ad9834_write(struct device *dev,
>  	}
>  	mutex_unlock(&st->lock);
>
> -error_ret:
>  	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 outreachy-kernel+unsubscribe@googlegroups.com.
> To post to this group, send email to outreachy-kernel@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/59ddccc600cfd1594dcb4dadb44b80328fc06008.1489356140.git.karniksayli1995%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Outreachy kernel] [PATCH v2 2/2] staging: iio: ad9834: Remove unnecessary goto label and compress return logic
  2017-03-12 22:27   ` [Outreachy kernel] " Alison Schofield
@ 2017-03-13  7:17     ` sayli karnik
  0 siblings, 0 replies; 6+ messages in thread
From: sayli karnik @ 2017-03-13  7:17 UTC (permalink / raw)
  To: Alison Schofield
  Cc: outreachy-kernel, Lars-Peter Clausen, Michael Hennerich,
	Jonathan Cameron, Hartmut Knaack, Peter Meerwald-Stadler,
	Greg Kroah-Hartman, linux-iio

On Mon, Mar 13, 2017 at 3:57 AM, Alison Schofield <amsfield22@gmail.com> wrote:
> On Mon, Mar 13, 2017 at 03:49:13AM +0530, sayli karnik wrote:
>> The patch removes excessive goto label and compresses return logic.
>>
>> Signed-off-by: sayli karnik <karniksayli1995@gmail.com>
>> ---
>>  drivers/staging/iio/frequency/ad9834.c | 6 ++----
>>  1 file changed, 2 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c
>> index 60461a6..18f3e8f 100644
>> --- a/drivers/staging/iio/frequency/ad9834.c
>> +++ b/drivers/staging/iio/frequency/ad9834.c
>> @@ -147,9 +147,8 @@ static ssize_t ad9834_write(struct device *dev,
>>       int ret;
>>       unsigned long val;
>>
>> -     ret = kstrtoul(buf, 10, &val);
>> -     if (ret)
>> -             goto error_ret;
>> +     if (kstrtoul(buf, 10, &val))
>> +             return kstrtoul(buf, 10, &val);
>
> Will a smaller change suffice?
>
Yes, sending a solution without having to call the function twice.

> ret = kstrtoul(buf, 10, &val);
> if (ret)
> -       goto error_ret;
> +       return ret;
>
> alisons
>
>>
>>       mutex_lock(&st->lock);
>>       switch ((u32)this_attr->address) {
>> @@ -211,7 +210,6 @@ static ssize_t ad9834_write(struct device *dev,
>>       }
>>       mutex_unlock(&st->lock);
>>
>> -error_ret:
>>       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 outreachy-kernel+unsubscribe@googlegroups.com.
>> To post to this group, send email to outreachy-kernel@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/59ddccc600cfd1594dcb4dadb44b80328fc06008.1489356140.git.karniksayli1995%40gmail.com.
>> 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 outreachy-kernel+unsubscribe@googlegroups.com.
> To post to this group, send email to outreachy-kernel@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20170312222738.GB14070%40d830.WORKGROUP.
> For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 6+ messages in thread

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

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-12 22:15 [PATCH v2 0/2] Replace mlock with private lock and improve code flow sayli karnik
2017-03-12 22:17 ` [PATCH v2 1/2] staging: iio: ad9834: Use private driver lock instead of mlock sayli karnik
2017-03-12 22:19 ` [PATCH v2 2/2] staging: iio: ad9834: Remove unnecessary goto label and compress return logic sayli karnik
2017-03-12 22:27   ` [Outreachy kernel] " Alison Schofield
2017-03-13  7:17     ` sayli karnik
2017-03-12 22:28   ` Julia Lawall

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.