Skip to contentSkip to conversation

extcon-max14577: Fine-tuning for max14577_muic_set_path()

PATCH Applied SF Markus Elfring 3 participants 10 messages Oct 22, 2017 – Oct 23, 2017

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

cover extcon-max14577: Fine-tuning for max14577_muic_set_path()

From: Markus Elfring <[email protected]>
Date: Sun, 22 Oct 2017 19:45:54 +0200

Two update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
Use common error handling code
Delete an unnecessary variable initialisation

 drivers/extcon/extcon-max14577.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)
Signature · 1 line
2.14.2
#1 lore raw

PATCH 1/2 extcon: max14577: Use common error handling code in max14577_muic_set_path()

From: Markus Elfring <[email protected]>
Date: Sun, 22 Oct 2017 19:33:58 +0200

Add a jump target so that a bit of exception handling can be better reused at the end of this function.

This issue was detected by using the Coccinelle software.

---
 drivers/extcon/extcon-max14577.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/extcon/extcon-max14577.c +10 -12
index f6414b7fa5bc..3d4bf5d23236 100644
@@ -211,10 +211,8 @@ static int max14577_muic_set_path(struct max14577_muic_info *info,
 	ret = max14577_update_reg(info->max14577->regmap,
 				MAX14577_MUIC_REG_CONTROL1,
 				CLEAR_IDBEN_MICEN_MASK, CTRL1_SW_OPEN);
-	if (ret < 0) {
-		dev_err(info->dev, "failed to update MUIC register\n");
-		return ret;
-	}
+	if (ret < 0)
+		goto report_failure;
 
 	if (attached)
 		ctrl1 = val;
@@ -224,10 +222,8 @@ static int max14577_muic_set_path(struct max14577_muic_info *info,
 	ret = max14577_update_reg(info->max14577->regmap,
 				MAX14577_MUIC_REG_CONTROL1,
 				CLEAR_IDBEN_MICEN_MASK, ctrl1);
-	if (ret < 0) {
-		dev_err(info->dev, "failed to update MUIC register\n");
-		return ret;
-	}
+	if (ret < 0)
+		goto report_failure;
 
 	if (attached)
 		ctrl2 |= CTRL2_CPEN_MASK;	/* LowPwr=0, CPEn=1 */
@@ -237,16 +233,18 @@ static int max14577_muic_set_path(struct max14577_muic_info *info,
 	ret = max14577_update_reg(info->max14577->regmap,
 			MAX14577_REG_CONTROL2,
 			CTRL2_LOWPWR_MASK | CTRL2_CPEN_MASK, ctrl2);
-	if (ret < 0) {
-		dev_err(info->dev, "failed to update MUIC register\n");
-		return ret;
-	}
+	if (ret < 0)
+		goto report_failure;
 
 	dev_dbg(info->dev,
 		"CONTROL1 : 0x%02x, CONTROL2 : 0x%02x, state : %s\n",
 		ctrl1, ctrl2, attached ? "attached" : "detached");
 
 	return 0;
+
+report_failure:
+	dev_err(info->dev, "failed to update MUIC register\n");
+	return ret;
 }
 
 /*
Signature · 1 line
2.14.2
#2 lore raw

Re: [PATCH 1/2] extcon: max14577: Use common error handling code in max14577_muic_set_path()

Quoted 18 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 22 Oct 2017 19:33:58 +0200

Add a jump target so that a bit of exception handling can be better reused at the end of this function.

This issue was detected by using the Coccinelle software.

---
 drivers/extcon/extcon-max14577.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/extcon/extcon-max14577.c +0 -0
index f6414b7fa5bc..3d4bf5d23236 100644

drivers/extcon/extcon-max14577.c static int max14577_muic_set_path(struct max14577_muic_info *info, · line 215

Quoted 9 lines
drivers/extcon/extcon-max14577.c +2 -4
@@ -211,10 +211,8 @@ static int max14577_muic_set_path(struct max14577_muic_info *info,
 	ret = max14577_update_reg(info->max14577->regmap,
 				MAX14577_MUIC_REG_CONTROL1,
 				CLEAR_IDBEN_MICEN_MASK, CTRL1_SW_OPEN);
-	if (ret < 0) {
-		dev_err(info->dev, "failed to update MUIC register\n");
-		return ret;
-	}
+	if (ret < 0)
+		goto report_failure;

No, one exit path just to report error does not seem to be more readable. Instead printing error after the register access looks to me as common pattern, easy to maintain.

This patch does not bring improvement, in my opinion.

Best regards,
Krzysztof

Quoted 42 lines
drivers/extcon/extcon-max14577.c +8 -8
 	if (attached)
 		ctrl1 = val;
@@ -224,10 +222,8 @@ static int max14577_muic_set_path(struct max14577_muic_info *info,
 	ret = max14577_update_reg(info->max14577->regmap,
 				MAX14577_MUIC_REG_CONTROL1,
 				CLEAR_IDBEN_MICEN_MASK, ctrl1);
-	if (ret < 0) {
-		dev_err(info->dev, "failed to update MUIC register\n");
-		return ret;
-	}
+	if (ret < 0)
+		goto report_failure;
 
 	if (attached)
 		ctrl2 |= CTRL2_CPEN_MASK;	/* LowPwr=0, CPEn=1 */
@@ -237,16 +233,18 @@ static int max14577_muic_set_path(struct max14577_muic_info *info,
 	ret = max14577_update_reg(info->max14577->regmap,
 			MAX14577_REG_CONTROL2,
 			CTRL2_LOWPWR_MASK | CTRL2_CPEN_MASK, ctrl2);
-	if (ret < 0) {
-		dev_err(info->dev, "failed to update MUIC register\n");
-		return ret;
-	}
+	if (ret < 0)
+		goto report_failure;
 
 	dev_dbg(info->dev,
 		"CONTROL1 : 0x%02x, CONTROL2 : 0x%02x, state : %s\n",
 		ctrl1, ctrl2, attached ? "attached" : "detached");
 
 	return 0;
+
+report_failure:
+	dev_err(info->dev, "failed to update MUIC register\n");
+	return ret;
 }
 
 /*
Signature · 1 line
2.14.2
#3 lore raw

Re: [PATCH 1/2] extcon: max14577: Use common error handling code in max14577_muic_set_path()

Quoted 13 lines
Quoted 13 lines

From: Markus Elfring <[email protected]>
Date: Sun, 22 Oct 2017 19:33:58 +0200

Add a jump target so that a bit of exception handling can be better reused at the end of this function.

This issue was detected by using the Coccinelle software.

---
 drivers/extcon/extcon-max14577.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
Quoted 16 lines
Quoted 5 lines
drivers/extcon/extcon-max14577.c +0 -0
index f6414b7fa5bc..3d4bf5d23236 100644

drivers/extcon/extcon-max14577.c static int max14577_muic_set_path(struct max14577_muic_info *info, · line 215

Quoted 9 lines
drivers/extcon/extcon-max14577.c +2 -4
@@ -211,10 +211,8 @@ static int max14577_muic_set_path(struct max14577_muic_info *info,
 	ret = max14577_update_reg(info->max14577->regmap,
 				MAX14577_MUIC_REG_CONTROL1,
 				CLEAR_IDBEN_MICEN_MASK, CTRL1_SW_OPEN);
-	if (ret < 0) {
-		dev_err(info->dev, "failed to update MUIC register\n");
-		return ret;
-	}
+	if (ret < 0)
+		goto report_failure;

No, one exit path just to report error does not seem to be more readable.

I got an other development opinion on this aspect.

Quoted 2 lines

Instead printing error after the register access looks to me as common pattern, easy to maintain.

Do you care if corresponding messages are different?

Quoted 1 line

This patch does not bring improvement, in my opinion.

How do you generally think about the change possibility for a bit of code reduction?

Quoted 38 lines
Quoted 38 lines
drivers/extcon/extcon-max14577.c +8 -8
 	if (attached)
 		ctrl1 = val;
@@ -224,10 +222,8 @@ static int max14577_muic_set_path(struct max14577_muic_info *info,
 	ret = max14577_update_reg(info->max14577->regmap,
 				MAX14577_MUIC_REG_CONTROL1,
 				CLEAR_IDBEN_MICEN_MASK, ctrl1);
-	if (ret < 0) {
-		dev_err(info->dev, "failed to update MUIC register\n");
-		return ret;
-	}
+	if (ret < 0)
+		goto report_failure;
 
 	if (attached)
 		ctrl2 |= CTRL2_CPEN_MASK;	/* LowPwr=0, CPEn=1 */
@@ -237,16 +233,18 @@ static int max14577_muic_set_path(struct max14577_muic_info *info,
 	ret = max14577_update_reg(info->max14577->regmap,
 			MAX14577_REG_CONTROL2,
 			CTRL2_LOWPWR_MASK | CTRL2_CPEN_MASK, ctrl2);
-	if (ret < 0) {
-		dev_err(info->dev, "failed to update MUIC register\n");
-		return ret;
-	}
+	if (ret < 0)
+		goto report_failure;
 
 	dev_dbg(info->dev,
 		"CONTROL1 : 0x%02x, CONTROL2 : 0x%02x, state : %s\n",
 		ctrl1, ctrl2, attached ? "attached" : "detached");
 
 	return 0;
+
+report_failure:
+	dev_err(info->dev, "failed to update MUIC register\n");
+	return ret;
 }
 
Quoted 4 lines
Quoted 4 lines
drivers/extcon/extcon-max14577.c +0 -0
 /*
Signature · 1 line
2.14.2

Would you like to take another look at remaining open issues in source files from the pattern “extcon-max…”?

Regards,
Markus

maintainer
#4 lore raw

Re: [PATCH 1/2] extcon: max14577: Use common error handling code in max14577_muic_set_path()

In reply to SF Markus Elfring

Hi,

As you commented, this patch might remove the redundant error message. But, it makes the code more complicated in side of readability.
If max1577_muic_set_path() have to handle the additional core and exception handling int the future, this patch might make it more difficult. So, I prefer existing code.

Thanks for your effort.

Regards,
Chanwoo Choi

Quoted 67 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 22 Oct 2017 19:33:58 +0200

Add a jump target so that a bit of exception handling can be better reused at the end of this function.

This issue was detected by using the Coccinelle software.

---
 drivers/extcon/extcon-max14577.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/extcon/extcon-max14577.c +10 -12
index f6414b7fa5bc..3d4bf5d23236 100644
@@ -211,10 +211,8 @@ static int max14577_muic_set_path(struct max14577_muic_info *info,
 	ret = max14577_update_reg(info->max14577->regmap,
 				MAX14577_MUIC_REG_CONTROL1,
 				CLEAR_IDBEN_MICEN_MASK, CTRL1_SW_OPEN);
-	if (ret < 0) {
-		dev_err(info->dev, "failed to update MUIC register\n");
-		return ret;
-	}
+	if (ret < 0)
+		goto report_failure;
 
 	if (attached)
 		ctrl1 = val;
@@ -224,10 +222,8 @@ static int max14577_muic_set_path(struct max14577_muic_info *info,
 	ret = max14577_update_reg(info->max14577->regmap,
 				MAX14577_MUIC_REG_CONTROL1,
 				CLEAR_IDBEN_MICEN_MASK, ctrl1);
-	if (ret < 0) {
-		dev_err(info->dev, "failed to update MUIC register\n");
-		return ret;
-	}
+	if (ret < 0)
+		goto report_failure;
 
 	if (attached)
 		ctrl2 |= CTRL2_CPEN_MASK;	/* LowPwr=0, CPEn=1 */
@@ -237,16 +233,18 @@ static int max14577_muic_set_path(struct max14577_muic_info *info,
 	ret = max14577_update_reg(info->max14577->regmap,
 			MAX14577_REG_CONTROL2,
 			CTRL2_LOWPWR_MASK | CTRL2_CPEN_MASK, ctrl2);
-	if (ret < 0) {
-		dev_err(info->dev, "failed to update MUIC register\n");
-		return ret;
-	}
+	if (ret < 0)
+		goto report_failure;
 
 	dev_dbg(info->dev,
 		"CONTROL1 : 0x%02x, CONTROL2 : 0x%02x, state : %s\n",
 		ctrl1, ctrl2, attached ? "attached" : "detached");
 
 	return 0;
+
+report_failure:
+	dev_err(info->dev, "failed to update MUIC register\n");
+	return ret;
 }
 
 /*
#5 lore raw

Re: [PATCH 1/2] extcon: max14577: Use common error handling code in max14577_muic_set_path()

Quoted 2 lines

As you commented, this patch might remove the redundant error message. But, it makes the code more complicated in side of readability.

Do you try to avoid duplicated code any more in other circumstances?

Regards,
Markus

maintainer
#6 lore raw

Re: [PATCH 1/2] extcon: max14577: Use common error handling code in max14577_muic_set_path()

Quoted 4 lines · SF Markus Elfring
Quoted 2 lines

As you commented, this patch might remove the redundant error message. But, it makes the code more complicated in side of readability.

Do you try to avoid duplicated code any more in other circumstances?

I usually used the goto statement on following cases:
- Return the value (error number if fail or 0 if success)
- Do free or unregister or remove operations when error happen.

I think that there is any benefit of this patch. Also, as I commented, it make the code more complicated.

Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics
#7 lore raw

Re: extcon: max14577: Use common error handling code in max14577_muic_set_path()

Quoted 2 lines

I think that there is any benefit of this patch. Also, as I commented, it make the code more complicated.

We have got different software development opinions about the shown change possibilities then.

Regards,
Markus

maintainer
#8 lore raw

Re: extcon: max14577: Use common error handling code in max14577_muic_set_path()

Quoted 4 lines · SF Markus Elfring
Quoted 2 lines

I think that there is any benefit of this patch. Also, as I commented, it make the code more complicated.

We have got different software development opinions about

I agree absolutely. So, anyone can suggest the opinion and send patches. But, all patches have to get the review from maintainer, reviewer or the mailing-list developer.

(Please don't remove the part of my comment when you reply.)

Quoted 1 line

the shown change possibilities then.

Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics
#9 lore raw

Re: extcon: max14577: Use common error handling code in max14577_muic_set_path()

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

I think that there is any benefit of this patch. Also, as I commented, it make the code more complicated.

We have got different software development opinions about

I agree absolutely. So, anyone can suggest the opinion and send patches. But, all patches have to get the review from maintainer, reviewer or the mailing-list developer.

Can an other change acceptance evolve over time?

Quoted 3 lines

(Please don't remove the part of my comment when you reply.)

Quoted 1 line

the shown change possibilities then.

Do you find similar updates more useful for any other software modules?

Regards,
Markus