OSDN Git Service

net: txgbe: Fix memleak in txgbe_calc_eeprom_checksum()
authorYueHaibing <yuehaibing@huawei.com>
Sat, 5 Nov 2022 08:07:21 +0000 (16:07 +0800)
committerJakub Kicinski <kuba@kernel.org>
Tue, 8 Nov 2022 04:00:09 +0000 (20:00 -0800)
eeprom_ptrs should be freed before returned.

Fixes: 049fe5365324 ("net: txgbe: Add operations to interact with firmware")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/wangxun/txgbe/txgbe_hw.c

index 0b10321..9cf5fe3 100644 (file)
@@ -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;
 }