diff mbox series

[net-next,1/2] net: txgbe: Fix memleak in txgbe_calc_eeprom_checksum()

Message ID 20221105080722.20292-2-yuehaibing@huawei.com (mailing list archive)
State Accepted
Commit a068d33e542f5d5be2e5de3cf1122c4347d3e2af
Delegated to: Netdev Maintainers
Headers show
Series net: txgbe: Fix two bugs in txgbe_calc_eeprom_checksum | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 23 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Yue Haibing Nov. 5, 2022, 8:07 a.m. UTC
eeprom_ptrs should be freed before returned.

Fixes: 049fe5365324 ("net: txgbe: Add operations to interact with firmware")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
 drivers/net/ethernet/wangxun/txgbe/txgbe_hw.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_hw.c b/drivers/net/ethernet/wangxun/txgbe/txgbe_hw.c
index 0b1032195859..9cf5fe33118e 100644
--- a/drivers/net/ethernet/wangxun/txgbe/txgbe_hw.c
+++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_hw.c
@@ -183,6 +183,7 @@  static int txgbe_calc_eeprom_checksum(struct txgbe_hw *hw, u16 *checksum)
 						  eeprom_ptrs);
 		if (status != 0) {
 			wx_err(wxhw, "Failed to read EEPROM image\n");
+			kvfree(eeprom_ptrs);
 			return status;
 		}
 		local_buffer = eeprom_ptrs;
@@ -196,13 +197,13 @@  static int txgbe_calc_eeprom_checksum(struct txgbe_hw *hw, u16 *checksum)
 		if (i != wxhw->eeprom.sw_region_offset + TXGBE_EEPROM_CHECKSUM)
 			*checksum += local_buffer[i];
 
+	if (eeprom_ptrs)
+		kvfree(eeprom_ptrs);
+
 	*checksum = TXGBE_EEPROM_SUM - *checksum;
 	if (*checksum < 0)
 		return -EINVAL;
 
-	if (eeprom_ptrs)
-		kvfree(eeprom_ptrs);
-
 	return 0;
 }