Skip to contentSkip to conversation

phylink: Use common error handling code in phylink_create()

PATCH In review SF Markus Elfring 3 participants 3 messages Oct 28, 2017

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

PATCH 1/1 phylink: Use common error handling code in phylink_create()

From: Markus Elfring <[email protected]>
Date: Sat, 28 Oct 2017 21:48:31 +0200

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

* Adjust three condition checks.

This issue was detected by using the Coccinelle software.

---
 drivers/net/phy/phylink.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/net/phy/phylink.c +10 -12
index bcb4755bcd95..67b19c13f405 100644
@@ -533,26 +533,24 @@ struct phylink *phylink_create(struct net_device *ndev, struct device_node *np,
 	phylink_validate(pl, pl->supported, &pl->link_config);
 
 	ret = phylink_parse_mode(pl, np);
-	if (ret < 0) {
-		kfree(pl);
-		return ERR_PTR(ret);
-	}
+	if (ret)
+		goto free_link;
 
 	if (pl->link_an_mode = MLO_AN_FIXED) {
 		ret = phylink_parse_fixedlink(pl, np);
-		if (ret < 0) {
-			kfree(pl);
-			return ERR_PTR(ret);
-		}
+		if (ret)
+			goto free_link;
 	}
 
 	ret = phylink_register_sfp(pl, np);
-	if (ret < 0) {
-		kfree(pl);
-		return ERR_PTR(ret);
-	}
+	if (ret)
+		goto free_link;
 
 	return pl;
+
+free_link:
+	kfree(pl);
+	return ERR_PTR(ret);
 }
 EXPORT_SYMBOL_GPL(phylink_create);
 
Signature · 1 line
2.14.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 28 Oct 2017 21:48:31 +0200

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

* Adjust three condition checks.

This issue was detected by using the Coccinelle software.

Signature · 1 line
Florian
maintainer Acked-by Russell King on v1 1/1
#2 lore raw
In reply to SF Markus Elfring
Quoted 11 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 28 Oct 2017 21:48:31 +0200

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

* Adjust three condition checks.

This issue was detected by using the Coccinelle software.

Thanks.

Quoted 48 lines
---
 drivers/net/phy/phylink.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/net/phy/phylink.c +10 -12
index bcb4755bcd95..67b19c13f405 100644
@@ -533,26 +533,24 @@ struct phylink *phylink_create(struct net_device *ndev, struct device_node *np,
 	phylink_validate(pl, pl->supported, &pl->link_config);
 
 	ret = phylink_parse_mode(pl, np);
-	if (ret < 0) {
-		kfree(pl);
-		return ERR_PTR(ret);
-	}
+	if (ret)
+		goto free_link;
 
 	if (pl->link_an_mode = MLO_AN_FIXED) {
 		ret = phylink_parse_fixedlink(pl, np);
-		if (ret < 0) {
-			kfree(pl);
-			return ERR_PTR(ret);
-		}
+		if (ret)
+			goto free_link;
 	}
 
 	ret = phylink_register_sfp(pl, np);
-	if (ret < 0) {
-		kfree(pl);
-		return ERR_PTR(ret);
-	}
+	if (ret)
+		goto free_link;
 
 	return pl;
+
+free_link:
+	kfree(pl);
+	return ERR_PTR(ret);
 }
 EXPORT_SYMBOL_GPL(phylink_create);
 
Signature · 1 line
2.14.3
Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 8.8Mbps down 630kbps up
According to speedtest.net: 8.21Mbps down 510kbps up