linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [media] ov5645: Move an error code assignment in ov5645_probe()
@ 2018-03-14 21:15 SF Markus Elfring
  2018-03-14 22:17 ` Sakari Ailus
  0 siblings, 1 reply; 4+ messages in thread
From: SF Markus Elfring @ 2018-03-14 21:15 UTC (permalink / raw)
  To: linux-media, Hans Verkuil, Mauro Carvalho Chehab, Sakari Ailus,
	Todor Tomov
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 14 Mar 2018 22:02:52 +0100

Move an assignment for a specific error code so that it is stored only once
in this function implementation.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/media/i2c/ov5645.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c
index d28845f7356f..374576380fd4 100644
--- a/drivers/media/i2c/ov5645.c
+++ b/drivers/media/i2c/ov5645.c
@@ -1284,13 +1284,11 @@ static int ov5645_probe(struct i2c_client *client,
 	ret = ov5645_read_reg(ov5645, OV5645_CHIP_ID_HIGH, &chip_id_high);
 	if (ret < 0 || chip_id_high != OV5645_CHIP_ID_HIGH_BYTE) {
 		dev_err(dev, "could not read ID high\n");
-		ret = -ENODEV;
 		goto power_down;
 	}
 	ret = ov5645_read_reg(ov5645, OV5645_CHIP_ID_LOW, &chip_id_low);
 	if (ret < 0 || chip_id_low != OV5645_CHIP_ID_LOW_BYTE) {
 		dev_err(dev, "could not read ID low\n");
-		ret = -ENODEV;
 		goto power_down;
 	}
 
@@ -1300,7 +1298,6 @@ static int ov5645_probe(struct i2c_client *client,
 			      &ov5645->aec_pk_manual);
 	if (ret < 0) {
 		dev_err(dev, "could not read AEC/AGC mode\n");
-		ret = -ENODEV;
 		goto power_down;
 	}
 
@@ -1308,7 +1305,6 @@ static int ov5645_probe(struct i2c_client *client,
 			      &ov5645->timing_tc_reg20);
 	if (ret < 0) {
 		dev_err(dev, "could not read vflip value\n");
-		ret = -ENODEV;
 		goto power_down;
 	}
 
@@ -1316,7 +1312,6 @@ static int ov5645_probe(struct i2c_client *client,
 			      &ov5645->timing_tc_reg21);
 	if (ret < 0) {
 		dev_err(dev, "could not read hflip value\n");
-		ret = -ENODEV;
 		goto power_down;
 	}
 
@@ -1334,6 +1329,7 @@ static int ov5645_probe(struct i2c_client *client,
 
 power_down:
 	ov5645_s_power(&ov5645->sd, false);
+	ret = -ENODEV;
 free_entity:
 	media_entity_cleanup(&ov5645->sd.entity);
 free_ctrl:
-- 
2.16.2

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

* Re: [PATCH] [media] ov5645: Move an error code assignment in ov5645_probe()
  2018-03-14 21:15 [PATCH] [media] ov5645: Move an error code assignment in ov5645_probe() SF Markus Elfring
@ 2018-03-14 22:17 ` Sakari Ailus
  2018-03-15  8:57   ` Todor Tomov
  2018-03-15  9:34   ` SF Markus Elfring
  0 siblings, 2 replies; 4+ messages in thread
From: Sakari Ailus @ 2018-03-14 22:17 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: linux-media, Hans Verkuil, Mauro Carvalho Chehab, Todor Tomov,
	LKML, kernel-janitors

On Wed, Mar 14, 2018 at 10:15:43PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 14 Mar 2018 22:02:52 +0100
> 
> Move an assignment for a specific error code so that it is stored only once
> in this function implementation.
> 
> This issue was detected by using the Coccinelle software.

How?

> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  drivers/media/i2c/ov5645.c | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c
> index d28845f7356f..374576380fd4 100644
> --- a/drivers/media/i2c/ov5645.c
> +++ b/drivers/media/i2c/ov5645.c
> @@ -1284,13 +1284,11 @@ static int ov5645_probe(struct i2c_client *client,
>  	ret = ov5645_read_reg(ov5645, OV5645_CHIP_ID_HIGH, &chip_id_high);
>  	if (ret < 0 || chip_id_high != OV5645_CHIP_ID_HIGH_BYTE) {
>  		dev_err(dev, "could not read ID high\n");
> -		ret = -ENODEV;
>  		goto power_down;
>  	}
>  	ret = ov5645_read_reg(ov5645, OV5645_CHIP_ID_LOW, &chip_id_low);
>  	if (ret < 0 || chip_id_low != OV5645_CHIP_ID_LOW_BYTE) {
>  		dev_err(dev, "could not read ID low\n");
> -		ret = -ENODEV;
>  		goto power_down;
>  	}
>  
> @@ -1300,7 +1298,6 @@ static int ov5645_probe(struct i2c_client *client,
>  			      &ov5645->aec_pk_manual);
>  	if (ret < 0) {
>  		dev_err(dev, "could not read AEC/AGC mode\n");
> -		ret = -ENODEV;
>  		goto power_down;
>  	}
>  
> @@ -1308,7 +1305,6 @@ static int ov5645_probe(struct i2c_client *client,
>  			      &ov5645->timing_tc_reg20);
>  	if (ret < 0) {
>  		dev_err(dev, "could not read vflip value\n");
> -		ret = -ENODEV;
>  		goto power_down;
>  	}
>  
> @@ -1316,7 +1312,6 @@ static int ov5645_probe(struct i2c_client *client,
>  			      &ov5645->timing_tc_reg21);
>  	if (ret < 0) {
>  		dev_err(dev, "could not read hflip value\n");
> -		ret = -ENODEV;
>  		goto power_down;
>  	}
>  
> @@ -1334,6 +1329,7 @@ static int ov5645_probe(struct i2c_client *client,
>  
>  power_down:
>  	ov5645_s_power(&ov5645->sd, false);
> +	ret = -ENODEV;

I don't think this is where people would expect you to set the error code
in general. It should rather take place before goto, not after it. That'd
mean another variable, and I'm not convinced the result would improve the
driver.

>  free_entity:
>  	media_entity_cleanup(&ov5645->sd.entity);
>  free_ctrl:

-- 
Regards,

Sakari Ailus
sakari.ailus@linux.intel.com

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

* Re: [PATCH] [media] ov5645: Move an error code assignment in ov5645_probe()
  2018-03-14 22:17 ` Sakari Ailus
@ 2018-03-15  8:57   ` Todor Tomov
  2018-03-15  9:34   ` SF Markus Elfring
  1 sibling, 0 replies; 4+ messages in thread
From: Todor Tomov @ 2018-03-15  8:57 UTC (permalink / raw)
  To: Sakari Ailus, SF Markus Elfring
  Cc: linux-media, Hans Verkuil, Mauro Carvalho Chehab, LKML, kernel-janitors

Hi,

On 15.03.2018 00:17, Sakari Ailus wrote:
> On Wed, Mar 14, 2018 at 10:15:43PM +0100, SF Markus Elfring wrote:
>> From: Markus Elfring <elfring@users.sourceforge.net>
>> Date: Wed, 14 Mar 2018 22:02:52 +0100
>>
>> Move an assignment for a specific error code so that it is stored only once
>> in this function implementation.
>>
>> This issue was detected by using the Coccinelle software.
> 
> How?
> 
>>
>> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
>> ---
>>  drivers/media/i2c/ov5645.c | 6 +-----
>>  1 file changed, 1 insertion(+), 5 deletions(-)
>>
>> diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c
>> index d28845f7356f..374576380fd4 100644
>> --- a/drivers/media/i2c/ov5645.c
>> +++ b/drivers/media/i2c/ov5645.c
>> @@ -1284,13 +1284,11 @@ static int ov5645_probe(struct i2c_client *client,
>>  	ret = ov5645_read_reg(ov5645, OV5645_CHIP_ID_HIGH, &chip_id_high);
>>  	if (ret < 0 || chip_id_high != OV5645_CHIP_ID_HIGH_BYTE) {
>>  		dev_err(dev, "could not read ID high\n");
>> -		ret = -ENODEV;
>>  		goto power_down;
>>  	}
>>  	ret = ov5645_read_reg(ov5645, OV5645_CHIP_ID_LOW, &chip_id_low);
>>  	if (ret < 0 || chip_id_low != OV5645_CHIP_ID_LOW_BYTE) {
>>  		dev_err(dev, "could not read ID low\n");
>> -		ret = -ENODEV;
>>  		goto power_down;
>>  	}
>>  
>> @@ -1300,7 +1298,6 @@ static int ov5645_probe(struct i2c_client *client,
>>  			      &ov5645->aec_pk_manual);
>>  	if (ret < 0) {
>>  		dev_err(dev, "could not read AEC/AGC mode\n");
>> -		ret = -ENODEV;
>>  		goto power_down;
>>  	}
>>  
>> @@ -1308,7 +1305,6 @@ static int ov5645_probe(struct i2c_client *client,
>>  			      &ov5645->timing_tc_reg20);
>>  	if (ret < 0) {
>>  		dev_err(dev, "could not read vflip value\n");
>> -		ret = -ENODEV;
>>  		goto power_down;
>>  	}
>>  
>> @@ -1316,7 +1312,6 @@ static int ov5645_probe(struct i2c_client *client,
>>  			      &ov5645->timing_tc_reg21);
>>  	if (ret < 0) {
>>  		dev_err(dev, "could not read hflip value\n");
>> -		ret = -ENODEV;
>>  		goto power_down;
>>  	}
>>  
>> @@ -1334,6 +1329,7 @@ static int ov5645_probe(struct i2c_client *client,
>>  
>>  power_down:
>>  	ov5645_s_power(&ov5645->sd, false);
>> +	ret = -ENODEV;
> 
> I don't think this is where people would expect you to set the error code
> in general. It should rather take place before goto, not after it. That'd
> mean another variable, and I'm not convinced the result would improve the
> driver.

I agree with Sakari.

> 
>>  free_entity:
>>  	media_entity_cleanup(&ov5645->sd.entity);
>>  free_ctrl:
> 

-- 
Best regards,
Todor Tomov

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

* Re: [media] ov5645: Move an error code assignment in ov5645_probe()
  2018-03-14 22:17 ` Sakari Ailus
  2018-03-15  8:57   ` Todor Tomov
@ 2018-03-15  9:34   ` SF Markus Elfring
  1 sibling, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2018-03-15  9:34 UTC (permalink / raw)
  To: Sakari Ailus, linux-media
  Cc: Hans Verkuil, Mauro Carvalho Chehab, Todor Tomov, LKML, kernel-janitors

>> Move an assignment for a specific error code so that it is stored only once
>> in this function implementation.
>>
>> This issue was detected by using the Coccinelle software.
> 
> How?

Would you like to experiment a bit more with the following approach
for the semantic patch language?

show_same_statements3.cocci:

@duplicated_code@
identifier work;
statement s1, s2;
type T;
@@
 T work(...)
 {
 ... when any
*if ((...) < 0)
*{
    ...
*   s1
*   s2
*}
 ... when any
*if ((...) < 0)
*{
    ...
*   s1
*   s2
*}
 ... when any
 }


>> @@ -1334,6 +1329,7 @@ static int ov5645_probe(struct i2c_client *client,
>>  
>>  power_down:
>>  	ov5645_s_power(&ov5645->sd, false);
>> +	ret = -ENODEV;
> 
> I don't think this is where people would expect you to set the error code
> in general.

This can be. - The view depends on some factors.


> It should rather take place before goto, not after it.

I proposed another software design direction.


> That'd mean another variable,

To which detail do you refer here?


> and I'm not convinced the result would improve the driver.

Can you see the relevance of a small code reduction in this function?

Regards,
Markus

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

end of thread, other threads:[~2018-03-15  9:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-14 21:15 [PATCH] [media] ov5645: Move an error code assignment in ov5645_probe() SF Markus Elfring
2018-03-14 22:17 ` Sakari Ailus
2018-03-15  8:57   ` Todor Tomov
2018-03-15  9:34   ` SF Markus Elfring

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