]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bnxt_en: Fix coredump logic to free allocated buffer
authorShruti Parab <shruti.parab@broadcom.com>
Mon, 28 Apr 2025 22:59:01 +0000 (15:59 -0700)
committerDavid S. Miller <davem@davemloft.net>
Wed, 30 Apr 2025 12:03:21 +0000 (13:03 +0100)
When handling HWRM_DBG_COREDUMP_LIST FW command in
bnxt_hwrm_dbg_dma_data(), the allocated buffer info->dest_buf is
not freed in the error path.  In the normal path, info->dest_buf
is assigned to coredump->data and it will eventually be freed after
the coredump is collected.

Free info->dest_buf immediately inside bnxt_hwrm_dbg_dma_data() in
the error path.

Fixes: c74751f4c392 ("bnxt_en: Return error if FW returns more data than dump length")
Reported-by: Michael Chan <michael.chan@broadcom.com>
Reviewed-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
Signed-off-by: Shruti Parab <shruti.parab@broadcom.com>
Signed-off-by: Michael Chan <michael.chan@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/broadcom/bnxt/bnxt_coredump.c

index 5576e7cf8463176c6350f3cf30d210dbd2a1b79c..9a74793648f69299e9780e839fd0e8cdb29aeeeb 100644 (file)
@@ -116,6 +116,11 @@ static int bnxt_hwrm_dbg_dma_data(struct bnxt *bp, void *msg,
                                memcpy(info->dest_buf + off, dma_buf, len);
                        } else {
                                rc = -ENOBUFS;
+                               if (cmn_req->req_type ==
+                                   cpu_to_le16(HWRM_DBG_COREDUMP_LIST)) {
+                                       kfree(info->dest_buf);
+                                       info->dest_buf = NULL;
+                               }
                                break;
                        }
                }