netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: netdev@vger.kernel.org, kernel-janitors@vger.kernel.org,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>,
	Jijie Shao <shaojijie@huawei.com>,
	Paolo Abeni <pabeni@redhat.com>,
	Salil Mehta <salil.mehta@huawei.com>,
	Wojciech Drewek <wojciech.drewek@intel.com>,
	Yisen Zhuang <yisen.zhuang@huawei.com>,
	Yonglong Liu <liuyonglong@huawei.com>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] net: hns: Use common error handling code in hns_mac_init()
Date: Fri, 1 Mar 2024 16:04:07 +0100	[thread overview]
Message-ID: <9a2e5053-07ec-4a11-bef4-7a8b0f80f740@web.de> (raw)

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


             reply	other threads:[~2024-03-01 15:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-01 15:04 Markus Elfring [this message]
2024-03-05 11:32 ` [PATCH] net: hns: Use common error handling code in hns_mac_init() Jijie Shao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9a2e5053-07ec-4a11-bef4-7a8b0f80f740@web.de \
    --to=markus.elfring@web.de \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liuyonglong@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=salil.mehta@huawei.com \
    --cc=shaojijie@huawei.com \
    --cc=wojciech.drewek@intel.com \
    --cc=yisen.zhuang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).