Commit 91c596cc authored by Jakub Kicinski's avatar Jakub Kicinski
Browse files

Merge branch 'net-txgbe-fix-two-bugs-in-txgbe_calc_eeprom_checksum'

YueHaibing says:

====================
net: txgbe: Fix two bugs in txgbe_calc_eeprom_checksum

Fix memleak and unsigned comparison bugs in txgbe_calc_eeprom_checksum
====================

Link: https://lore.kernel.org/r/20221105080722.20292-1-yuehaibing@huawei.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 49eb9446 5e2ea780
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -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,14 @@ 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];

	*checksum = TXGBE_EEPROM_SUM - *checksum;
	if (*checksum < 0)
		return -EINVAL;

	if (eeprom_ptrs)
		kvfree(eeprom_ptrs);

	if (*checksum > TXGBE_EEPROM_SUM)
		return -EINVAL;

	*checksum = TXGBE_EEPROM_SUM - *checksum;

	return 0;
}