Skip to contentSkip to conversation

media: staging: atomisp: Removed else branch in function

PATCH In review Leonid Kushnir 3 participants 3 messages Oct 6, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 media: staging: atomisp: Removed else branch in function

This patch fixes the checkpatch.pl warning :

WARNING: else is not generally useful after a break or return

Expressions under 'else' branch in function 'gc0310_s_power' are executed whenever the exppression in 'if' is False. Otherwise, return from function occurs. Therefore, there is no need in 'else', and it has been removed.

---
 drivers/staging/media/atomisp/i2c/atomisp-gc0310.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/staging/media/atomisp/i2c/atomisp-gc0310.c +4 -5
index 6be3ee1d93a5..8201c15b5769 100644
@@ -874,11 +874,10 @@ static int gc0310_s_power(struct v4l2_subdev *sd, int on)
 
 	if (on == 0)
 		return power_down(sd);
-	else {
-		ret = power_up(sd);
-		if (!ret)
-			return gc0310_init(sd);
-	}
+	ret = power_up(sd);
+	if (!ret)
+		return gc0310_init(sd);
+
 	return ret;
 }
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 19 lines · Leonid Kushnir

This patch fixes the checkpatch.pl warning :

WARNING: else is not generally useful after a break or return

Expressions under 'else' branch in function 'gc0310_s_power' are executed whenever the exppression in 'if' is False. Otherwise, return from function occurs. Therefore, there is no need in 'else', and it has been removed.

---
 drivers/staging/media/atomisp/i2c/atomisp-gc0310.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/staging/media/atomisp/i2c/atomisp-gc0310.c +0 -0
index 6be3ee1d93a5..8201c15b5769 100644

drivers/staging/media/atomisp/i2c/atomisp-gc0310.c static int gc0310_s_power(struct v4l2_subdev *sd, int on) · line 878

Quoted 10 lines
drivers/staging/media/atomisp/i2c/atomisp-gc0310.c +2 -5
@@ -874,11 +874,10 @@ static int gc0310_s_power(struct v4l2_subdev *sd, int on)
 
 	if (on == 0)
 		return power_down(sd);
-	else {
-		ret = power_up(sd);
-		if (!ret)
-			return gc0310_init(sd);
-	}
+	ret = power_up(sd);
+	if (!ret)

Flip this check around as well.

drivers/staging/media/atomisp/i2c/atomisp-gc0310.c static int gc0310_s_power(struct v4l2_subdev *sd, int on) · line 881

Quoted 3 lines
drivers/staging/media/atomisp/i2c/atomisp-gc0310.c +2 -0
+		return gc0310_init(sd);
+
 	return ret;

Code should generally do "error handling" instead of "success handling". That way the success path is always indented one tab and the error path is indented two tabs. I like to say that the call and the error handling are part of the same thing, but with success handling, it's like do the call, do more stuff, go back to the error handling from the earlier call.

Anyway, TLDR, please write it like this:

	if (on == 0)

return power_down(sd);

	ret = power_up(sd);
	if (ret)
		return ret;

	return gc0310_init(sd);

regards,
dan carpenter

#2 lore raw
Quoted 1 line · Dan Carpenter

Code should generally do "error handling" instead of "success handling".

Maybe something to add to coding-style
(in '6} Functions' maybe?)...

Quoted 5 lines

That way the success path is always indented one tab and the error path is indented two tabs. I like to say that the call and the error handling are part of the same thing, but with success handling, it's like do the call, do more stuff, go back to the error handling from the earlier call.

[]

Quoted 10 lines

Anyway, TLDR, please write it like this:

	if (on == 0)

return power_down(sd);

	ret = power_up(sd);
	if (ret)
		return ret;

	return gc0310_init(sd);

Much nicer, thanks for taking the time to write it.