Skip to contentSkip to conversation

net: hns: Use common error handling code in hns_mac_init()

PATCH In review Markus Elfring 2 participants 2 messages Mar 1, 2024 – Mar 5, 2024

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

PATCH 1/1 net: hns: Use common error handling code in hns_mac_init()

From: Markus Elfring <[email protected]>
Date: Fri, 1 Mar 2024 15:48:25 +0100

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

---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c +9 -6
index f75668c47935..a4919aad45b6 100644
@@ -1094,22 +1094,21 @@ int hns_mac_init(struct dsaf_device *dsaf_dev)
 	device_for_each_child_node(dsaf_dev->dev, child) {
 		ret = fwnode_property_read_u32(child, "reg", &port_id);
 		if (ret) {
-			fwnode_handle_put(child);
 			dev_err(dsaf_dev->dev,
 				"get reg fail, ret=%d!\n", ret);
-			return ret;
+			goto put_fwnode;
 		}
 		if (port_id >= max_port_num) {
-			fwnode_handle_put(child);
 			dev_err(dsaf_dev->dev,
 				"reg(%u) out of range!\n", port_id);
-			return -EINVAL;
+			ret = -EINVAL;
+			goto put_fwnode;
 		}
 		mac_cb = devm_kzalloc(dsaf_dev->dev, sizeof(*mac_cb),
 				      GFP_KERNEL);
 		if (!mac_cb) {
-			fwnode_handle_put(child);
-			return -ENOMEM;
+			ret = -ENOMEM;
+			goto put_fwnode;
 		}
 		mac_cb->fw_port = child;
 		mac_cb->mac_id = (u8)port_id;
@@ -1148,6 +1147,10 @@ int hns_mac_init(struct dsaf_device *dsaf_dev)
 	}
 
 	return 0;
+
+put_fwnode:
+	fwnode_handle_put(child);
+	return ret;
 }
 
 void hns_mac_uninit(struct dsaf_device *dsaf_dev)

--
2.44.0

maintainer Reviewed-by on v1 1/1
#1 lore raw

Thanks,

Quoted 57 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 1 Mar 2024 15:48:25 +0100

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

---
  drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 15 +++++++++------
  1 file changed, 9 insertions(+), 6 deletions(-)
drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c +9 -7
index f75668c47935..a4919aad45b6 100644
@@ -1094,22 +1094,21 @@ int hns_mac_init(struct dsaf_device *dsaf_dev)
  	device_for_each_child_node(dsaf_dev->dev, child) {
  		ret = fwnode_property_read_u32(child, "reg", &port_id);
  		if (ret) {
-			fwnode_handle_put(child);
  			dev_err(dsaf_dev->dev,
  				"get reg fail, ret=%d!\n", ret);
-			return ret;
+			goto put_fwnode;
  		}
  		if (port_id >= max_port_num) {
-			fwnode_handle_put(child);
  			dev_err(dsaf_dev->dev,
  				"reg(%u) out of range!\n", port_id);
-			return -EINVAL;
+			ret = -EINVAL;
+			goto put_fwnode;
  		}
  		mac_cb = devm_kzalloc(dsaf_dev->dev, sizeof(*mac_cb),
  				      GFP_KERNEL);
  		if (!mac_cb) {
-			fwnode_handle_put(child);
-			return -ENOMEM;
+			ret = -ENOMEM;
+			goto put_fwnode;
  		}
  		mac_cb->fw_port = child;
  		mac_cb->mac_id = (u8)port_id;
@@ -1148,6 +1147,10 @@ int hns_mac_init(struct dsaf_device *dsaf_dev)
  	}
 
  	return 0;
+
+put_fwnode:
+	fwnode_handle_put(child);
+	return ret;
  }
 
  void hns_mac_uninit(struct dsaf_device *dsaf_dev)
--

2.44.0