* [PATCH] qlcnic: Use common error handling code in four functions
@ 2024-09-19 19:50 Markus Elfring
2024-09-22 16:56 ` Simon Horman
0 siblings, 1 reply; 2+ messages in thread
From: Markus Elfring @ 2024-09-19 19:50 UTC (permalink / raw)
To: GR-Linux-NIC-Dev, netdev, David S. Miller, Eric Dumazet,
Himanshu Madhani, Jakub Kicinski, Manish Chopra, Paolo Abeni,
Shahed Shaikh
Cc: LKML, kernel-janitors, Manish Chopra
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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] qlcnic: Use common error handling code in four functions
2024-09-19 19:50 [PATCH] qlcnic: Use common error handling code in four functions Markus Elfring
@ 2024-09-22 16:56 ` Simon Horman
0 siblings, 0 replies; 2+ messages in thread
From: Simon Horman @ 2024-09-22 16:56 UTC (permalink / raw)
To: Markus Elfring
Cc: GR-Linux-NIC-Dev, netdev, David S. Miller, Eric Dumazet,
Himanshu Madhani, Jakub Kicinski, Manish Chopra, Paolo Abeni,
Shahed Shaikh, LKML, kernel-janitors, Manish Chopra
On Thu, Sep 19, 2024 at 09:50:13PM +0200, Markus Elfring wrote:
> 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>
Hi Markus,
This is an old driver, that doesn't appear to have been under active
development for quite some time. Unless there is a way to exercise these
changes I don't think that clean-ups of this nature are worth the risk of
regressions they might introduce.
If we can see bugs in error paths, let's fix them.
Else, let's leave them be.
--
pw-bot: rejected
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-09-22 16:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-19 19:50 [PATCH] qlcnic: Use common error handling code in four functions Markus Elfring
2024-09-22 16:56 ` Simon Horman
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).