staging: iio: addac: Remove unnecessary else after return in if block
Subsystems (4)
PATCH 1/1 staging: iio: addac: Remove unnecessary else after return in if block
Else is unncessary when there is an return statement in the corresponding if block. Remove else and refactor code. Coccinelle patch used:
@rule1@
expression e1;
@@
if (e1) { ... return ...; }
- else{
...- }
@rule2@
expression e2;
statement s1;
@@
if(e2) { ... return ...; }
- else
s1--- drivers/staging/iio/addac/adt7316.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/staging/iio/addac/adt7316.c +2 -3
@@ -465,8 +465,7 @@ static ssize_t adt7316_show_all_ad_channels(struct device *dev,return sprintf (buf,"0 - VDD\n1 - Internal Temperature\n" "2 - External Temperature or AIN1\n" "3 - AIN2\n4 - AIN3\n5 - AIN4\n" ); - else - return sprintf(buf, "0 - VDD\n1 - Internal Temperature\n" +return sprintf (buf,"0 - VDD\n1 - Internal Temperature\n" "2 - External Temperature\n" ); }
@@ -637,7 +636,7 @@ static ssize_t adt7316_show_da_high_resolution(struct device *dev,if (chip->config3 &ADT7316_DA_HIGH_RESOLUTION ) {if (chip->id ==ID_ADT7316 || chip->id ==ID_ADT7516 )return sprintf (buf,"1 (12 bits)\n" ); -else if (chip->id ==ID_ADT7317 || chip->id ==ID_ADT7517 ) +if (chip->id ==ID_ADT7317 || chip->id ==ID_ADT7517 )return sprintf (buf,"1 (10 bits)\n" ); }
Signature · 1 line
2.5.0
Quoted 33 lines · Janani Ravichandran
Else is unncessary when there is an return statement in the corresponding if block. Remove else and refactor code. Coccinelle patch used:
@rule1@
expression e1;
@@if (e1) { ... return ...; }(quoted diff) +0
-2- else{ - }@rule2@
expression e2;
statement s1;
@@if(e2) { ... return ...; } - else s1Signed-off-by Janani Ravichandran <[email protected]>--- drivers/staging/iio/addac/adt7316.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/staging/iio/addac/adt7316.c +0
-0
drivers/staging/iio/addac/adt7316.c static ssize_t adt7316_show_all_ad_channels(struct device *dev, · line 469
Quoted 7 lines
drivers/staging/iio/addac/adt7316.c +1
-2@@ -465,8 +465,7 @@ static ssize_t adt7316_show_all_ad_channels(struct device *dev,return sprintf (buf,"0 - VDD\n1 - Internal Temperature\n" "2 - External Temperature or AIN1\n" "3 - AIN2\n4 - AIN3\n5 - AIN4\n" ); - else - return sprintf(buf, "0 - VDD\n1 - Internal Temperature\n" +return sprintf (buf,"0 - VDD\n1 - Internal Temperature\n" "2 - External Temperature\n" );
While touching this, you can also fix the alignment for the second line
CHECK: Alignment should match open parenthesis
Quoted 12 lines
drivers/staging/iio/addac/adt7316.c +1
-2}@@ -637,7 +636,7 @@ static ssize_t adt7316_show_da_high_resolution(struct device *dev,if (chip->config3 &ADT7316_DA_HIGH_RESOLUTION ) {if (chip->id ==ID_ADT7316 || chip->id ==ID_ADT7516 )return sprintf (buf,"1 (12 bits)\n" ); -else if (chip->id ==ID_ADT7317 || chip->id ==ID_ADT7517 ) +if (chip->id ==ID_ADT7317 || chip->id ==ID_ADT7517 )return sprintf (buf,"1 (10 bits)\n" ); } --
Quoted 26 lines · Daniel Baluta
Quoted 23 lines · Janani Ravichandran
Else is unncessary when there is an return statement in the corresponding if block. Remove else and refactor code. Coccinelle patch used:
@rule1@
expression e1;
@@if (e1) { ... return ...; }(quoted diff) +0
-2- else{ - }@rule2@
expression e2;
statement s1;
@@if(e2) { ... return ...; } - else s1
Quoted 6 lines
Review
Quoted 6 lines
Signed-off-by Janani Ravichandran <[email protected]>--- drivers/staging/iio/addac/adt7316.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)(quoted diff) +0
-0
b/drivers/staging/iio/addac/adt7316.c
Quoted 4 lines
drivers/staging/iio/addac/adt7316.c static ssize_t adt7316_show_all_ad_channels(struct
Quoted 4 lines
index 3adc451..4a88a85 100644
drivers/staging/iio/addac/adt7316.c +0
-0@@ -465,8 +465,7 @@ static ssize_t adt7316_show_all_ad_channels(struct
device *dev,
Quoted 1 line
drivers/staging/iio/addac/adt7316.c static ssize_t adt7316_show_all_ad_channels(struct · line 465
Quoted 1 line
drivers/staging/iio/addac/adt7316.c +0
-0return sprintf(buf, "0 - VDD\n1 - Internal
Temperature\n"
Quoted 4 lines
drivers/staging/iio/addac/adt7316.c static ssize_t adt7316_show_all_ad_channels(struct device *dev,
Quoted 4 lines
drivers/staging/iio/addac/adt7316.c +0
-2"2 - External Temperature or AIN1\n" "3 - AIN2\n4 - AIN3\n5 - AIN4\n"); - else - return sprintf(buf, "0 - VDD\n1 - Internal
Temperature\n"
Quoted 6 lines
drivers/staging/iio/addac/adt7316.c static ssize_t adt7316_show_all_ad_channels(struct device *dev, · line 469
Quoted 2 lines
drivers/staging/iio/addac/adt7316.c +1
-0+return sprintf (buf,"0 - VDD\n1 - Internal Temperature\n" "2 - External Temperature\n" );While touching this, you can also fix the alignment for the second line
CHECK: Alignment should match open parenthesis
Sure, Daniel. I will send a v2 for this. Thanks!
Janani.
Quoted 3 lines
drivers/staging/iio/addac/adt7316.c static ssize_t
Quoted 3 lines
drivers/staging/iio/addac/adt7316.c +0
-0}@@ -637,7 +636,7 @@ static ssize_t
adt7316_show_da_high_resolution(struct device *dev,
Quoted 4 lines
drivers/staging/iio/addac/adt7316.c static ssize_t adt7316_show_da_high_resolution(struct device *dev,
Quoted 4 lines
drivers/staging/iio/addac/adt7316.c +0
-1if (chip->config3 &ADT7316_DA_HIGH_RESOLUTION ) {if (chip->id ==ID_ADT7316 || chip->id ==ID_ADT7516 )return sprintf (buf,"1 (12 bits)\n" ); - else if (chip->id == ID_ADT7317 || chip->id ==
ID_ADT7517)
Quoted 5 lines
Quoted 5 lines
drivers/staging/iio/addac/adt7316.c +1
-1+if (chip->id ==ID_ADT7317 || chip->id ==ID_ADT7517 )return sprintf (buf,"1 (10 bits)\n" ); } --