From: Markus Elfring <Markus.Elfring@web.de>
To: GR-Linux-NIC-Dev@marvell.com, netdev@vger.kernel.org,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Himanshu Madhani <himanshu.madhani@qlogic.com>,
Jakub Kicinski <kuba@kernel.org>,
Manish Chopra <manishc@marvell.com>,
Paolo Abeni <pabeni@redhat.com>,
Shahed Shaikh <shshaikh@marvell.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
kernel-janitors@vger.kernel.org,
Manish Chopra <manish.chopra@qlogic.com>
Subject: [PATCH] qlcnic: Use common error handling code in four functions
Date: Thu, 19 Sep 2024 21:50:13 +0200 [thread overview]
Message-ID: <7c98349a-bfa5-409b-847e-ed8439e80afd@web.de> (raw)
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 19 Sep 2024 21:30:45 +0200
Add jump targets so that a bit of exception handling can be better reused
at the end of four function implementations.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
.../ethernet/qlogic/qlcnic/qlcnic_83xx_init.c | 12 +--
.../net/ethernet/qlogic/qlcnic/qlcnic_sysfs.c | 86 ++++++++-----------
2 files changed, 42 insertions(+), 56 deletions(-)
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
index b733374b4dc5..a8eaf10d9158 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
@@ -1333,17 +1333,13 @@ static int qlcnic_83xx_copy_bootloader(struct qlcnic_adapter *adapter)
ret = qlcnic_83xx_lockless_flash_read32(adapter, src, p_cache,
size / sizeof(u32));
- if (ret) {
- vfree(p_cache);
- return ret;
- }
+ if (ret)
+ goto free_cache;
+
/* 16 byte write to MS memory */
ret = qlcnic_ms_mem_write128(adapter, dest, (u32 *)p_cache,
size / 16);
- if (ret) {
- vfree(p_cache);
- return ret;
- }
+free_cache:
vfree(p_cache);
return ret;
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sysfs.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sysfs.c
index 74125188beb8..da1a6e68daf9 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sysfs.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sysfs.c
@@ -959,8 +959,8 @@ static ssize_t qlcnic_83xx_sysfs_flash_read_handler(struct file *filp,
if (!p_read_buf)
return -ENOMEM;
if (qlcnic_83xx_lock_flash(adapter) != 0) {
- kfree(p_read_buf);
- return -EIO;
+ ret = -EIO;
+ goto free_read_buf;
}
ret = qlcnic_83xx_lockless_flash_read32(adapter, offset, p_read_buf,
@@ -968,8 +968,7 @@ static ssize_t qlcnic_83xx_sysfs_flash_read_handler(struct file *filp,
if (ret) {
qlcnic_83xx_unlock_flash(adapter);
- kfree(p_read_buf);
- return ret;
+ goto free_read_buf;
}
qlcnic_83xx_unlock_flash(adapter);
@@ -978,6 +977,10 @@ static ssize_t qlcnic_83xx_sysfs_flash_read_handler(struct file *filp,
kfree(p_read_buf);
return size;
+
+free_read_buf:
+ kfree(p_read_buf);
+ return ret;
}
static int qlcnic_83xx_sysfs_flash_bulk_write(struct qlcnic_adapter *adapter,
@@ -996,18 +999,13 @@ static int qlcnic_83xx_sysfs_flash_bulk_write(struct qlcnic_adapter *adapter,
memcpy(p_cache, buf, size);
p_src = p_cache;
- if (qlcnic_83xx_lock_flash(adapter) != 0) {
- kfree(p_cache);
- return -EIO;
- }
+ if (qlcnic_83xx_lock_flash(adapter))
+ goto free_cache;
if (adapter->ahw->fdt.mfg_id == adapter->flash_mfg_id) {
ret = qlcnic_83xx_enable_flash_write(adapter);
- if (ret) {
- kfree(p_cache);
- qlcnic_83xx_unlock_flash(adapter);
- return -EIO;
- }
+ if (ret)
+ goto unlock_adapter;
}
for (i = 0; i < count / QLC_83XX_FLASH_WRITE_MAX; i++) {
@@ -1018,16 +1016,11 @@ static int qlcnic_83xx_sysfs_flash_bulk_write(struct qlcnic_adapter *adapter,
if (ret) {
if (adapter->ahw->fdt.mfg_id == adapter->flash_mfg_id) {
ret = qlcnic_83xx_disable_flash_write(adapter);
- if (ret) {
- kfree(p_cache);
- qlcnic_83xx_unlock_flash(adapter);
- return -EIO;
- }
+ if (ret)
+ goto unlock_adapter;
}
- kfree(p_cache);
- qlcnic_83xx_unlock_flash(adapter);
- return -EIO;
+ goto unlock_adapter;
}
p_src = p_src + sizeof(u32)*QLC_83XX_FLASH_WRITE_MAX;
@@ -1036,17 +1029,20 @@ static int qlcnic_83xx_sysfs_flash_bulk_write(struct qlcnic_adapter *adapter,
if (adapter->ahw->fdt.mfg_id == adapter->flash_mfg_id) {
ret = qlcnic_83xx_disable_flash_write(adapter);
- if (ret) {
- kfree(p_cache);
- qlcnic_83xx_unlock_flash(adapter);
- return -EIO;
- }
+ if (ret)
+ goto unlock_adapter;
}
kfree(p_cache);
qlcnic_83xx_unlock_flash(adapter);
return 0;
+
+unlock_adapter:
+ qlcnic_83xx_unlock_flash(adapter);
+free_cache:
+ kfree(p_cache);
+ return -EIO;
}
static int qlcnic_83xx_sysfs_flash_write(struct qlcnic_adapter *adapter,
@@ -1064,18 +1060,13 @@ static int qlcnic_83xx_sysfs_flash_write(struct qlcnic_adapter *adapter,
p_src = p_cache;
count = size / sizeof(u32);
- if (qlcnic_83xx_lock_flash(adapter) != 0) {
- kfree(p_cache);
- return -EIO;
- }
+ if (qlcnic_83xx_lock_flash(adapter))
+ goto free_cache;
if (adapter->ahw->fdt.mfg_id == adapter->flash_mfg_id) {
ret = qlcnic_83xx_enable_flash_write(adapter);
- if (ret) {
- kfree(p_cache);
- qlcnic_83xx_unlock_flash(adapter);
- return -EIO;
- }
+ if (ret)
+ goto unlock_adapter;
}
for (i = 0; i < count; i++) {
@@ -1083,15 +1074,11 @@ static int qlcnic_83xx_sysfs_flash_write(struct qlcnic_adapter *adapter,
if (ret) {
if (adapter->ahw->fdt.mfg_id == adapter->flash_mfg_id) {
ret = qlcnic_83xx_disable_flash_write(adapter);
- if (ret) {
- kfree(p_cache);
- qlcnic_83xx_unlock_flash(adapter);
- return -EIO;
- }
+ if (ret)
+ goto unlock_adapter;
}
- kfree(p_cache);
- qlcnic_83xx_unlock_flash(adapter);
- return -EIO;
+
+ goto unlock_adapter;
}
p_src = p_src + sizeof(u32);
@@ -1100,17 +1087,20 @@ static int qlcnic_83xx_sysfs_flash_write(struct qlcnic_adapter *adapter,
if (adapter->ahw->fdt.mfg_id == adapter->flash_mfg_id) {
ret = qlcnic_83xx_disable_flash_write(adapter);
- if (ret) {
- kfree(p_cache);
- qlcnic_83xx_unlock_flash(adapter);
- return -EIO;
- }
+ if (ret)
+ goto unlock_adapter;
}
kfree(p_cache);
qlcnic_83xx_unlock_flash(adapter);
return 0;
+
+unlock_adapter:
+ qlcnic_83xx_unlock_flash(adapter);
+free_cache:
+ kfree(p_cache);
+ return -EIO;
}
static ssize_t qlcnic_83xx_sysfs_flash_write_handler(struct file *filp,
--
2.46.0
next reply other threads:[~2024-09-19 19:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-19 19:50 Markus Elfring [this message]
2024-09-22 16:56 ` [PATCH] qlcnic: Use common error handling code in four functions Simon Horman
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=7c98349a-bfa5-409b-847e-ed8439e80afd@web.de \
--to=markus.elfring@web.de \
--cc=GR-Linux-NIC-Dev@marvell.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=himanshu.madhani@qlogic.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=manish.chopra@qlogic.com \
--cc=manishc@marvell.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shshaikh@marvell.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