net/bnxt: fix memory leaks in NVM commands
authorAjit Khaparde <ajit.khaparde@broadcom.com>
Thu, 26 Jul 2018 01:15:45 +0000 (18:15 -0700)
committerThomas Monjalon <thomas@monjalon.net>
Thu, 2 Aug 2018 10:05:25 +0000 (12:05 +0200)
In some cases we may not be freeing up memory allocated for certain
NVM commands because the code might have bailed out before reaching
rte_free(). This patch moves some code around to ensure the allocated
memory is freed before exiting the function.

Fixes: 19e6af01bb36 ("net/bnxt: support get/set EEPROM")
Cc: stable@dpdk.org
Signed-off-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
Reviewed-by: Somnath Kotur <somnath.kotur@broadcom.com>
Reviewed-by: Ray Jui <ray.jui@broadcom.com>
Reviewed-by: Michael Wildt <michael.wildt@broadcom.com>
Reviewed-by: Randy Schacher <stuart.schacher@broadcom.com>
drivers/net/bnxt/bnxt_hwrm.c

index 69c83cd..3f8e26c 100644 (file)
@@ -3353,13 +3353,12 @@ int bnxt_get_nvram_directory(struct bnxt *bp, uint32_t len, uint8_t *data)
        req.host_dest_addr = rte_cpu_to_le_64(dma_handle);
        rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
 
-       HWRM_CHECK_RESULT();
-       HWRM_UNLOCK();
-
        if (rc == 0)
                memcpy(data, buf, len > buflen ? buflen : len);
 
        rte_free(buf);
+       HWRM_CHECK_RESULT();
+       HWRM_UNLOCK();
 
        return rc;
 }
@@ -3391,12 +3390,13 @@ int bnxt_hwrm_get_nvram_item(struct bnxt *bp, uint32_t index,
        req.offset = rte_cpu_to_le_32(offset);
        req.len = rte_cpu_to_le_32(length);
        rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
-       HWRM_CHECK_RESULT();
-       HWRM_UNLOCK();
        if (rc == 0)
                memcpy(data, buf, length);
 
        rte_free(buf);
+       HWRM_CHECK_RESULT();
+       HWRM_UNLOCK();
+
        return rc;
 }
 
@@ -3451,10 +3451,10 @@ int bnxt_hwrm_flash_nvram(struct bnxt *bp, uint16_t dir_type,
 
        rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
 
+       rte_free(buf);
        HWRM_CHECK_RESULT();
        HWRM_UNLOCK();
 
-       rte_free(buf);
        return rc;
 }