linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: iio: accel: remove impossible condition
@ 2016-05-31 19:47 Luis de Bethencourt
  2016-05-31 20:13 ` Andrew F. Davis
  2016-05-31 20:23 ` Jonathan Cameron
  0 siblings, 2 replies; 4+ messages in thread
From: Luis de Bethencourt @ 2016-05-31 19:47 UTC (permalink / raw)
  To: linux-kernel
  Cc: gregkh, knaack.h, lars, jic23, ciorneiioana, janani.rvchndrn,
	afd, linux-iio, devel, Luis de Bethencourt

val is set to the value of ret right after ret is checked. If ret is not
zero it goes to error_ret. So only value ret can have is zero, which makes
the switch (val & 0x03) only match the case 0x00. Removing the switch and
since val is only used for this, removing val as well.

Signed-off-by: Luis de Bethencourt <luisbg@osg.samsung.com>
---
 drivers/staging/iio/accel/sca3000_core.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/iio/accel/sca3000_core.c b/drivers/staging/iio/accel/sca3000_core.c
index a8f533a..94656f6 100644
--- a/drivers/staging/iio/accel/sca3000_core.c
+++ b/drivers/staging/iio/accel/sca3000_core.c
@@ -586,7 +586,7 @@ static ssize_t sca3000_read_frequency(struct device *dev,
 {
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
 	struct sca3000_state *st = iio_priv(indio_dev);
-	int ret, len = 0, base_freq = 0, val;
+	int ret, len = 0, base_freq = 0;
 
 	mutex_lock(&st->lock);
 	ret = __sca3000_get_base_freq(st, st->info, &base_freq);
@@ -596,20 +596,8 @@ static ssize_t sca3000_read_frequency(struct device *dev,
 	mutex_unlock(&st->lock);
 	if (ret)
 		goto error_ret;
-	val = ret;
 	if (base_freq > 0)
-		switch (val & 0x03) {
-		case 0x00:
-		case 0x03:
-			len = sprintf(buf, "%d\n", base_freq);
-			break;
-		case 0x01:
-			len = sprintf(buf, "%d\n", base_freq / 2);
-			break;
-		case 0x02:
-			len = sprintf(buf, "%d\n", base_freq / 4);
-			break;
-	}
+		len = sprintf(buf, "%d\n", base_freq);
 
 	return len;
 error_ret_mut:
-- 
2.5.1

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

* Re: [PATCH] staging: iio: accel: remove impossible condition
  2016-05-31 19:47 [PATCH] staging: iio: accel: remove impossible condition Luis de Bethencourt
@ 2016-05-31 20:13 ` Andrew F. Davis
  2016-05-31 20:23 ` Jonathan Cameron
  1 sibling, 0 replies; 4+ messages in thread
From: Andrew F. Davis @ 2016-05-31 20:13 UTC (permalink / raw)
  To: Luis de Bethencourt, linux-kernel
  Cc: gregkh, knaack.h, lars, jic23, ciorneiioana, janani.rvchndrn,
	linux-iio, devel

On 05/31/2016 02:47 PM, Luis de Bethencourt wrote:
> val is set to the value of ret right after ret is checked. If ret is not
> zero it goes to error_ret. So only value ret can have is zero, which makes
> the switch (val & 0x03) only match the case 0x00. Removing the switch and
> since val is only used for this, removing val as well.
> 
> Signed-off-by: Luis de Bethencourt <luisbg@osg.samsung.com>
> ---
>  drivers/staging/iio/accel/sca3000_core.c | 16 ++--------------
>  1 file changed, 2 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/staging/iio/accel/sca3000_core.c b/drivers/staging/iio/accel/sca3000_core.c
> index a8f533a..94656f6 100644
> --- a/drivers/staging/iio/accel/sca3000_core.c
> +++ b/drivers/staging/iio/accel/sca3000_core.c
> @@ -586,7 +586,7 @@ static ssize_t sca3000_read_frequency(struct device *dev,
>  {
>  	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
>  	struct sca3000_state *st = iio_priv(indio_dev);
> -	int ret, len = 0, base_freq = 0, val;
> +	int ret, len = 0, base_freq = 0;
>  
>  	mutex_lock(&st->lock);
>  	ret = __sca3000_get_base_freq(st, st->info, &base_freq);
> @@ -596,20 +596,8 @@ static ssize_t sca3000_read_frequency(struct device *dev,
>  	mutex_unlock(&st->lock);
>  	if (ret)

I'm not sure, but I'm guessing this switch serves some purpose and this
was meant to be (ret < 0).

>  		goto error_ret;
> -	val = ret;
>  	if (base_freq > 0)
> -		switch (val & 0x03) {
> -		case 0x00:
> -		case 0x03:
> -			len = sprintf(buf, "%d\n", base_freq);
> -			break;
> -		case 0x01:
> -			len = sprintf(buf, "%d\n", base_freq / 2);
> -			break;
> -		case 0x02:
> -			len = sprintf(buf, "%d\n", base_freq / 4);
> -			break;
> -	}
> +		len = sprintf(buf, "%d\n", base_freq);
>  
>  	return len;
>  error_ret_mut:
> 

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

* Re: [PATCH] staging: iio: accel: remove impossible condition
  2016-05-31 19:47 [PATCH] staging: iio: accel: remove impossible condition Luis de Bethencourt
  2016-05-31 20:13 ` Andrew F. Davis
@ 2016-05-31 20:23 ` Jonathan Cameron
  2016-05-31 20:53   ` Luis de Bethencourt
  1 sibling, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2016-05-31 20:23 UTC (permalink / raw)
  To: Luis de Bethencourt, linux-kernel
  Cc: gregkh, knaack.h, lars, ciorneiioana, janani.rvchndrn, afd,
	linux-iio, devel



On 31 May 2016 20:47:50 BST, Luis de Bethencourt <luisbg@osg.samsung.com> wrote:
>val is set to the value of ret right after ret is checked. If ret is
>not
>zero it goes to error_ret. So only value ret can have is zero, which
>makes
>the switch (val & 0x03) only match the case 0x00. Removing the switch
>and
>since val is only used for this, removing val as well.
There is clearly an issue here. However it looks like it is that if(ret) which is wrong.

The code as it stands clearly doesn't work as intended. Fixing the bug would be

 more useful than removing code that 'should' be accessible.

I happen to fire the relevant hardware up yesterday for the first time in a while so

can easily verify the operation of a fix if you want to take another look.

Jonathan
>
>Signed-off-by: Luis de Bethencourt <luisbg@osg.samsung.com>
>---
> drivers/staging/iio/accel/sca3000_core.c | 16 ++--------------
> 1 file changed, 2 insertions(+), 14 deletions(-)
>
>diff --git a/drivers/staging/iio/accel/sca3000_core.c
>b/drivers/staging/iio/accel/sca3000_core.c
>index a8f533a..94656f6 100644
>--- a/drivers/staging/iio/accel/sca3000_core.c
>+++ b/drivers/staging/iio/accel/sca3000_core.c
>@@ -586,7 +586,7 @@ static ssize_t sca3000_read_frequency(struct device
>*dev,
> {
> 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> 	struct sca3000_state *st = iio_priv(indio_dev);
>-	int ret, len = 0, base_freq = 0, val;
>+	int ret, len = 0, base_freq = 0;
> 
> 	mutex_lock(&st->lock);
> 	ret = __sca3000_get_base_freq(st, st->info, &base_freq);
>@@ -596,20 +596,8 @@ static ssize_t sca3000_read_frequency(struct
>device *dev,
> 	mutex_unlock(&st->lock);
> 	if (ret)
> 		goto error_ret;
>-	val = ret;
> 	if (base_freq > 0)
>-		switch (val & 0x03) {
>-		case 0x00:
>-		case 0x03:
>-			len = sprintf(buf, "%d\n", base_freq);
>-			break;
>-		case 0x01:
>-			len = sprintf(buf, "%d\n", base_freq / 2);
>-			break;
>-		case 0x02:
>-			len = sprintf(buf, "%d\n", base_freq / 4);
>-			break;
>-	}
>+		len = sprintf(buf, "%d\n", base_freq);
> 
> 	return len;
> error_ret_mut:

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.

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

* Re: [PATCH] staging: iio: accel: remove impossible condition
  2016-05-31 20:23 ` Jonathan Cameron
@ 2016-05-31 20:53   ` Luis de Bethencourt
  0 siblings, 0 replies; 4+ messages in thread
From: Luis de Bethencourt @ 2016-05-31 20:53 UTC (permalink / raw)
  To: Jonathan Cameron, linux-kernel
  Cc: gregkh, knaack.h, lars, ciorneiioana, janani.rvchndrn, afd,
	linux-iio, devel

On 31/05/16 21:23, Jonathan Cameron wrote:
> 
> 
> On 31 May 2016 20:47:50 BST, Luis de Bethencourt <luisbg@osg.samsung.com> wrote:
>> val is set to the value of ret right after ret is checked. If ret is
>> not
>> zero it goes to error_ret. So only value ret can have is zero, which
>> makes
>> the switch (val & 0x03) only match the case 0x00. Removing the switch
>> and
>> since val is only used for this, removing val as well.
> There is clearly an issue here. However it looks like it is that if(ret) which is wrong.
> 
> The code as it stands clearly doesn't work as intended. Fixing the bug would be
> 
>  more useful than removing code that 'should' be accessible.
> 
> I happen to fire the relevant hardware up yesterday for the first time in a while so
> 
> can easily verify the operation of a fix if you want to take another look.
> 
> Jonathan

Jonathan and Andrew are right.

sca3000_read_ctrl_reg() returns a negative number on failure.

So line 597 should be: if (ret < 0)

If everything goes well in sca3000_read_ctrl_reg() it returns st->rx[0], which explains
the switch case.

I am going to send a new patch with this fix.

Thanks so much for the review and sorry for the initial confusion,
Luis

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

end of thread, other threads:[~2016-05-31 20:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-31 19:47 [PATCH] staging: iio: accel: remove impossible condition Luis de Bethencourt
2016-05-31 20:13 ` Andrew F. Davis
2016-05-31 20:23 ` Jonathan Cameron
2016-05-31 20:53   ` Luis de Bethencourt

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).