]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
net: e1000: Free temporary buffer on exit
authorAndrew Goodbody <andrew.goodbody@linaro.org>
Mon, 4 Aug 2025 15:32:51 +0000 (16:32 +0100)
committerTom Rini <trini@konsulko.com>
Thu, 14 Aug 2025 16:58:40 +0000 (10:58 -0600)
In do_e1000_spi_checksum a temporary buffer is allocated but never
freed. Add code to free on exit. Also refactor the code to make the exit
code common.

This issue found by Smatch.

Signed-off-by: Andrew Goodbody <andrew.goodbody@linaro.org>
drivers/net/e1000_spi.c

index 1e830b99f1d4564e99b98b87ad18962e2848b17d..33d38b57824ba3fe8cfe27cb26f589cf333022a6 100644 (file)
@@ -472,6 +472,7 @@ static int do_e1000_spi_checksum(struct cmd_tbl *cmdtp, struct e1000_hw *hw,
        uint16_t i, length, checksum = 0, checksum_reg;
        uint16_t *buffer;
        bool upd;
+       int ret = 0;
 
        if (argc == 0)
                upd = 0;
@@ -493,14 +494,15 @@ static int do_e1000_spi_checksum(struct cmd_tbl *cmdtp, struct e1000_hw *hw,
        /* Acquire the EEPROM */
        if (e1000_acquire_eeprom(hw)) {
                E1000_ERR(hw, "EEPROM SPI cannot be acquired!\n");
-               return 1;
+               ret = 1;
+               goto free_exit;
        }
 
        /* Read the EEPROM */
        if (e1000_spi_eeprom_dump(hw, buffer, 0, length, true) < 0) {
                E1000_ERR(hw, "Interrupted!\n");
-               e1000_release_eeprom(hw);
-               return 1;
+               ret = 1;
+               goto release_exit;
        }
 
        /* Compute the checksum and read the expected value */
@@ -513,8 +515,8 @@ static int do_e1000_spi_checksum(struct cmd_tbl *cmdtp, struct e1000_hw *hw,
        if (checksum_reg == checksum) {
                printf("%s: INFO: EEPROM checksum is correct! (0x%04hx)\n",
                                hw->name, checksum);
-               e1000_release_eeprom(hw);
-               return 0;
+               ret = 0;
+               goto release_exit;
        }
 
        /* Hrm, verification failed, print an error */
@@ -524,8 +526,8 @@ static int do_e1000_spi_checksum(struct cmd_tbl *cmdtp, struct e1000_hw *hw,
 
        /* If they didn't ask us to update it, just return an error */
        if (!upd) {
-               e1000_release_eeprom(hw);
-               return 1;
+               ret = 1;
+               goto release_exit;
        }
 
        /* Ok, correct it! */
@@ -534,12 +536,15 @@ static int do_e1000_spi_checksum(struct cmd_tbl *cmdtp, struct e1000_hw *hw,
        if (e1000_spi_eeprom_program(hw, &buffer[i], i * sizeof(uint16_t),
                        sizeof(uint16_t), true)) {
                E1000_ERR(hw, "Interrupted!\n");
-               e1000_release_eeprom(hw);
-               return 1;
+               ret = 1;
+               /* goto release_exit; */
        }
 
+release_exit:
        e1000_release_eeprom(hw);
-       return 0;
+free_exit:
+       free(buffer);
+       return ret;
 }
 
 int do_e1000_spi(struct cmd_tbl *cmdtp, struct e1000_hw *hw,