linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] staging: iio: ad799x: cleanup probe error handling
@ 2014-04-30 10:08 Dan Carpenter
  2014-04-30 12:00 ` Lars-Peter Clausen
  2014-04-30 20:37 ` Hartmut Knaack
  0 siblings, 2 replies; 6+ messages in thread
From: Dan Carpenter @ 2014-04-30 10:08 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Lars-Peter Clausen, Hartmut Knaack, Greg Kroah-Hartman,
	Randy Dunlap, Aida Mynzhasova, Masanari Iida, linux-iio,
	kernel-janitors

My static checker is upset that we check IS_ERR(t->reg) when we know it
is not an ERR_PTR().  The code is harmless but I have cleaned it up and
removed the condition.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
index 16a8b14..5c95cd9 100644
--- a/drivers/iio/adc/ad799x.c
+++ b/drivers/iio/adc/ad799x.c
@@ -717,7 +717,7 @@ static int ad799x_probe(struct i2c_client *client,
 	ret = iio_triggered_buffer_setup(indio_dev, NULL,
 		&ad799x_trigger_handler, NULL);
 	if (ret)
-		goto error_disable_reg;
+		goto error_disable_vref;
 
 	if (client->irq > 0) {
 		ret = devm_request_threaded_irq(&client->dev,
@@ -739,11 +739,10 @@ static int ad799x_probe(struct i2c_client *client,
 
 error_cleanup_ring:
 	iio_triggered_buffer_cleanup(indio_dev);
+error_disable_vref:
+	regulator_disable(st->vref);
 error_disable_reg:
-	if (!IS_ERR(st->vref))
-		regulator_disable(st->vref);
-	if (!IS_ERR(st->reg))
-		regulator_disable(st->reg);
+	regulator_disable(st->reg);
 
 	return ret;
 }

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

* Re: [patch] staging: iio: ad799x: cleanup probe error handling
  2014-04-30 10:08 [patch] staging: iio: ad799x: cleanup probe error handling Dan Carpenter
@ 2014-04-30 12:00 ` Lars-Peter Clausen
  2014-04-30 20:37 ` Hartmut Knaack
  1 sibling, 0 replies; 6+ messages in thread
From: Lars-Peter Clausen @ 2014-04-30 12:00 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Jonathan Cameron, Hartmut Knaack, Greg Kroah-Hartman,
	Randy Dunlap, Aida Mynzhasova, Masanari Iida, linux-iio,
	kernel-janitors

On 04/30/2014 12:08 PM, Dan Carpenter wrote:
> My static checker is upset that we check IS_ERR(t->reg) when we know it
> is not an ERR_PTR().  The code is harmless but I have cleaned it up and
> removed the condition.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Yea, I think that's a left over of another cleanup. Thanks.

Acked-by: Lars-Peter Clausen <lars@metafoo.de>

>
> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
> index 16a8b14..5c95cd9 100644
> --- a/drivers/iio/adc/ad799x.c
> +++ b/drivers/iio/adc/ad799x.c
> @@ -717,7 +717,7 @@ static int ad799x_probe(struct i2c_client *client,
>   	ret = iio_triggered_buffer_setup(indio_dev, NULL,
>   		&ad799x_trigger_handler, NULL);
>   	if (ret)
> -		goto error_disable_reg;
> +		goto error_disable_vref;
>
>   	if (client->irq > 0) {
>   		ret = devm_request_threaded_irq(&client->dev,
> @@ -739,11 +739,10 @@ static int ad799x_probe(struct i2c_client *client,
>
>   error_cleanup_ring:
>   	iio_triggered_buffer_cleanup(indio_dev);
> +error_disable_vref:
> +	regulator_disable(st->vref);
>   error_disable_reg:
> -	if (!IS_ERR(st->vref))
> -		regulator_disable(st->vref);
> -	if (!IS_ERR(st->reg))
> -		regulator_disable(st->reg);
> +	regulator_disable(st->reg);
>
>   	return ret;
>   }
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

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

* Re: [patch] staging: iio: ad799x: cleanup probe error handling
  2014-04-30 10:08 [patch] staging: iio: ad799x: cleanup probe error handling Dan Carpenter
  2014-04-30 12:00 ` Lars-Peter Clausen
@ 2014-04-30 20:37 ` Hartmut Knaack
  2014-04-30 21:05   ` [patch v2] [patch] staging: iio: ad799x: remove some unneeded IS_ERR() checks Dan Carpenter
  1 sibling, 1 reply; 6+ messages in thread
From: Hartmut Knaack @ 2014-04-30 20:37 UTC (permalink / raw)
  To: Dan Carpenter, Jonathan Cameron
  Cc: Lars-Peter Clausen, Greg Kroah-Hartman, Randy Dunlap,
	Aida Mynzhasova, Masanari Iida, linux-iio, kernel-janitors

Dan Carpenter schrieb:
> My static checker is upset that we check IS_ERR(t->reg) when we know it
> is not an ERR_PTR().  The code is harmless but I have cleaned it up and
> removed the condition.
Good spot. But doesn't that also apply to the two checks in ad799x_remove()?
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
> index 16a8b14..5c95cd9 100644
> --- a/drivers/iio/adc/ad799x.c
> +++ b/drivers/iio/adc/ad799x.c
> @@ -717,7 +717,7 @@ static int ad799x_probe(struct i2c_client *client,
>  	ret = iio_triggered_buffer_setup(indio_dev, NULL,
>  		&ad799x_trigger_handler, NULL);
>  	if (ret)
> -		goto error_disable_reg;
> +		goto error_disable_vref;
>  
>  	if (client->irq > 0) {
>  		ret = devm_request_threaded_irq(&client->dev,
> @@ -739,11 +739,10 @@ static int ad799x_probe(struct i2c_client *client,
>  
>  error_cleanup_ring:
>  	iio_triggered_buffer_cleanup(indio_dev);
> +error_disable_vref:
> +	regulator_disable(st->vref);
>  error_disable_reg:
> -	if (!IS_ERR(st->vref))
> -		regulator_disable(st->vref);
> -	if (!IS_ERR(st->reg))
> -		regulator_disable(st->reg);
> +	regulator_disable(st->reg);
>  
>  	return ret;
>  }
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>


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

* [patch v2] [patch] staging: iio: ad799x: remove some unneeded IS_ERR() checks
  2014-04-30 20:37 ` Hartmut Knaack
@ 2014-04-30 21:05   ` Dan Carpenter
  2014-04-30 21:52     ` Hartmut Knaack
  0 siblings, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2014-04-30 21:05 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Lars-Peter Clausen, Hartmut Knaack, Greg Kroah-Hartman,
	Randy Dunlap, Aida Mynzhasova, Masanari Iida, linux-iio,
	linux-kernel, kernel-janitors

My static checker is upset that we check IS_ERR(t->reg) when we know it
is not an ERR_PTR.

Checking for IS_ERR() twice is often a sign of confusion and buggy code.
In this case, if the call to "ret = regulator_enable(st->vref);" fails,
then we call "regulator_disable(st->vref);" and that's a mistake because
"st->vref" is not enabled.

I fixed these problems and Hartmut Knaack pointed out a couple unneeded
IS_ERR() checks in ad799x_remove() so I have removed those as well.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: remove the unneeded checks in ad799x_remove() as well.  Updated the
    commit message to say that it's actually a small bug fix.

diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
index 16a8b14..39b4cb4 100644
--- a/drivers/iio/adc/ad799x.c
+++ b/drivers/iio/adc/ad799x.c
@@ -717,7 +717,7 @@ static int ad799x_probe(struct i2c_client *client,
 	ret = iio_triggered_buffer_setup(indio_dev, NULL,
 		&ad799x_trigger_handler, NULL);
 	if (ret)
-		goto error_disable_reg;
+		goto error_disable_vref;
 
 	if (client->irq > 0) {
 		ret = devm_request_threaded_irq(&client->dev,
@@ -739,11 +739,10 @@ static int ad799x_probe(struct i2c_client *client,
 
 error_cleanup_ring:
 	iio_triggered_buffer_cleanup(indio_dev);
+error_disable_vref:
+	regulator_disable(st->vref);
 error_disable_reg:
-	if (!IS_ERR(st->vref))
-		regulator_disable(st->vref);
-	if (!IS_ERR(st->reg))
-		regulator_disable(st->reg);
+	regulator_disable(st->reg);
 
 	return ret;
 }
@@ -756,10 +755,8 @@ static int ad799x_remove(struct i2c_client *client)
 	iio_device_unregister(indio_dev);
 
 	iio_triggered_buffer_cleanup(indio_dev);
-	if (!IS_ERR(st->vref))
-		regulator_disable(st->vref);
-	if (!IS_ERR(st->reg))
-		regulator_disable(st->reg);
+	regulator_disable(st->vref);
+	regulator_disable(st->reg);
 	kfree(st->rx_buf);
 
 	return 0;

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

* Re: [patch v2] [patch] staging: iio: ad799x: remove some unneeded IS_ERR() checks
  2014-04-30 21:05   ` [patch v2] [patch] staging: iio: ad799x: remove some unneeded IS_ERR() checks Dan Carpenter
@ 2014-04-30 21:52     ` Hartmut Knaack
  2014-05-03 10:17       ` Jonathan Cameron
  0 siblings, 1 reply; 6+ messages in thread
From: Hartmut Knaack @ 2014-04-30 21:52 UTC (permalink / raw)
  To: Dan Carpenter, Jonathan Cameron
  Cc: Lars-Peter Clausen, Greg Kroah-Hartman, Randy Dunlap,
	Aida Mynzhasova, Masanari Iida, linux-iio, linux-kernel,
	kernel-janitors

Dan Carpenter schrieb:
> My static checker is upset that we check IS_ERR(t->reg) when we know it
> is not an ERR_PTR.
>
> Checking for IS_ERR() twice is often a sign of confusion and buggy code.
> In this case, if the call to "ret = regulator_enable(st->vref);" fails,
> then we call "regulator_disable(st->vref);" and that's a mistake because
> "st->vref" is not enabled.
>
> I fixed these problems and Hartmut Knaack pointed out a couple unneeded
> IS_ERR() checks in ad799x_remove() so I have removed those as well.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Hartmut Knaack <knaack.h@gmx.de>
> ---
> v2: remove the unneeded checks in ad799x_remove() as well.  Updated the
>     commit message to say that it's actually a small bug fix.
>
> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
> index 16a8b14..39b4cb4 100644
> --- a/drivers/iio/adc/ad799x.c
> +++ b/drivers/iio/adc/ad799x.c
> @@ -717,7 +717,7 @@ static int ad799x_probe(struct i2c_client *client,
>  	ret = iio_triggered_buffer_setup(indio_dev, NULL,
>  		&ad799x_trigger_handler, NULL);
>  	if (ret)
> -		goto error_disable_reg;
> +		goto error_disable_vref;
>  
>  	if (client->irq > 0) {
>  		ret = devm_request_threaded_irq(&client->dev,
> @@ -739,11 +739,10 @@ static int ad799x_probe(struct i2c_client *client,
>  
>  error_cleanup_ring:
>  	iio_triggered_buffer_cleanup(indio_dev);
> +error_disable_vref:
> +	regulator_disable(st->vref);
>  error_disable_reg:
> -	if (!IS_ERR(st->vref))
> -		regulator_disable(st->vref);
> -	if (!IS_ERR(st->reg))
> -		regulator_disable(st->reg);
> +	regulator_disable(st->reg);
>  
>  	return ret;
>  }
> @@ -756,10 +755,8 @@ static int ad799x_remove(struct i2c_client *client)
>  	iio_device_unregister(indio_dev);
>  
>  	iio_triggered_buffer_cleanup(indio_dev);
> -	if (!IS_ERR(st->vref))
> -		regulator_disable(st->vref);
> -	if (!IS_ERR(st->reg))
> -		regulator_disable(st->reg);
> +	regulator_disable(st->vref);
> +	regulator_disable(st->reg);
>  	kfree(st->rx_buf);
>  
>  	return 0;
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

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

* Re: [patch v2] [patch] staging: iio: ad799x: remove some unneeded IS_ERR() checks
  2014-04-30 21:52     ` Hartmut Knaack
@ 2014-05-03 10:17       ` Jonathan Cameron
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2014-05-03 10:17 UTC (permalink / raw)
  To: Hartmut Knaack, Dan Carpenter
  Cc: Lars-Peter Clausen, Greg Kroah-Hartman, Randy Dunlap,
	Aida Mynzhasova, Masanari Iida, linux-iio, linux-kernel,
	kernel-janitors

On 30/04/14 22:52, Hartmut Knaack wrote:
> Dan Carpenter schrieb:
>> My static checker is upset that we check IS_ERR(t->reg) when we know it
>> is not an ERR_PTR.
>>
>> Checking for IS_ERR() twice is often a sign of confusion and buggy code.
>> In this case, if the call to "ret = regulator_enable(st->vref);" fails,
>> then we call "regulator_disable(st->vref);" and that's a mistake because
>> "st->vref" is not enabled.
>>
>> I fixed these problems and Hartmut Knaack pointed out a couple unneeded
>> IS_ERR() checks in ad799x_remove() so I have removed those as well.
>>
>> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> Acked-by: Hartmut Knaack <knaack.h@gmx.de>
Thanks to both of you for this.

Applied to the togreg branch of iio.git as the cleanup that caused
this was most likely part of a series that is only in staging-next at
the moment.

Jonathan

>> ---
>> v2: remove the unneeded checks in ad799x_remove() as well.  Updated the
>>      commit message to say that it's actually a small bug fix.
>>
>> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
>> index 16a8b14..39b4cb4 100644
>> --- a/drivers/iio/adc/ad799x.c
>> +++ b/drivers/iio/adc/ad799x.c
>> @@ -717,7 +717,7 @@ static int ad799x_probe(struct i2c_client *client,
>>   	ret = iio_triggered_buffer_setup(indio_dev, NULL,
>>   		&ad799x_trigger_handler, NULL);
>>   	if (ret)
>> -		goto error_disable_reg;
>> +		goto error_disable_vref;
>>
>>   	if (client->irq > 0) {
>>   		ret = devm_request_threaded_irq(&client->dev,
>> @@ -739,11 +739,10 @@ static int ad799x_probe(struct i2c_client *client,
>>
>>   error_cleanup_ring:
>>   	iio_triggered_buffer_cleanup(indio_dev);
>> +error_disable_vref:
>> +	regulator_disable(st->vref);
>>   error_disable_reg:
>> -	if (!IS_ERR(st->vref))
>> -		regulator_disable(st->vref);
>> -	if (!IS_ERR(st->reg))
>> -		regulator_disable(st->reg);
>> +	regulator_disable(st->reg);
>>
>>   	return ret;
>>   }
>> @@ -756,10 +755,8 @@ static int ad799x_remove(struct i2c_client *client)
>>   	iio_device_unregister(indio_dev);
>>
>>   	iio_triggered_buffer_cleanup(indio_dev);
>> -	if (!IS_ERR(st->vref))
>> -		regulator_disable(st->vref);
>> -	if (!IS_ERR(st->reg))
>> -		regulator_disable(st->reg);
>> +	regulator_disable(st->vref);
>> +	regulator_disable(st->reg);
>>   	kfree(st->rx_buf);
>>
>>   	return 0;
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>
>


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

end of thread, other threads:[~2014-05-03 10:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-30 10:08 [patch] staging: iio: ad799x: cleanup probe error handling Dan Carpenter
2014-04-30 12:00 ` Lars-Peter Clausen
2014-04-30 20:37 ` Hartmut Knaack
2014-04-30 21:05   ` [patch v2] [patch] staging: iio: ad799x: remove some unneeded IS_ERR() checks Dan Carpenter
2014-04-30 21:52     ` Hartmut Knaack
2014-05-03 10:17       ` Jonathan Cameron

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