[PATCH] qlcnic: Use common error handling code in four functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
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@xxxxxxxxxxxxxxxxxxxxx>
---
 .../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






[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux