OSDN Git Service

net: txgbe: Fix unsigned comparison to zero in txgbe_calc_eeprom_checksum()
authorYueHaibing <yuehaibing@huawei.com>
Sat, 5 Nov 2022 08:07:22 +0000 (16:07 +0800)
committerJakub Kicinski <kuba@kernel.org>
Tue, 8 Nov 2022 04:00:10 +0000 (20:00 -0800)
The error checks on checksum for a negative error return always fails because
it is unsigned and can never be negative.

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 9cf5fe3..167f7ff 100644 (file)
@@ -200,10 +200,11 @@ static int txgbe_calc_eeprom_checksum(struct txgbe_hw *hw, u16 *checksum)
        if (eeprom_ptrs)
                kvfree(eeprom_ptrs);
 
-       *checksum = TXGBE_EEPROM_SUM - *checksum;
-       if (*checksum < 0)
+       if (*checksum > TXGBE_EEPROM_SUM)
                return -EINVAL;
 
+       *checksum = TXGBE_EEPROM_SUM - *checksum;
+
        return 0;
 }