diff mbox series

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

Message ID 9a2e5053-07ec-4a11-bef4-7a8b0f80f740@web.de (mailing list archive)
State Rejected
Delegated to: Netdev Maintainers
Headers show
Series net: hns: Use common error handling code in hns_mac_init() | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 940 this patch: 940
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 1 maintainers not CCed: elfring@users.sourceforge.net
netdev/build_clang success Errors and warnings before: 956 this patch: 956
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 956 this patch: 956
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 37 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-03-02--12-00 (tests: 884)

Commit Message

Markus Elfring March 1, 2024, 3:04 p.m. UTC
From: Markus Elfring <elfring@users.sourceforge.net>
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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

--
2.44.0

Comments

Jijie Shao March 5, 2024, 11:32 a.m. UTC | #1
Thanks,
Reviewed-by: Jijie Shao<shaojijie@huawei.com>

on 2024/3/1 23:04, Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> 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.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>   drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 15 +++++++++------
>   1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
> index f75668c47935..a4919aad45b6 100644
> --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
> +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
> @@ -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
>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
index f75668c47935..a4919aad45b6 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
@@ -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)