From f0ceb70cb93afb7d18afde19b738d2976dd3611a Mon Sep 17 00:00:00 2001 From: Joseph Wong Date: Mon, 23 Feb 2026 14:03:47 -0800 Subject: [PATCH] [bnxt] Fix memory leak in probe() Fix potential memory leak in probe() if initialization fails after HWRM memory has been allocated. Signed-off-by: Joseph Wong --- src/drivers/net/bnxt/bnxt.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/drivers/net/bnxt/bnxt.c b/src/drivers/net/bnxt/bnxt.c index e49734699..94865bf60 100644 --- a/src/drivers/net/bnxt/bnxt.c +++ b/src/drivers/net/bnxt/bnxt.c @@ -2816,18 +2816,18 @@ static int bnxt_init_one ( struct pci_device *pci ) bnxt_get_pci_info ( bp ); /* Allocate HWRM memory */ - bnxt_alloc_hwrm_mem ( bp ); + if ( ( err = bnxt_alloc_hwrm_mem ( bp ) ) != 0 ) + goto err_alloc_hwrm; bp->link_status = STATUS_LINK_DOWN; bp->wait_link_timeout = LINK_DEFAULT_TIMEOUT; - if ( bnxt_up_init ( bp ) != 0 ) { - goto err_down_chip; - } + if ( ( err = bnxt_up_init ( bp ) ) != 0 ) + goto err_up_init; /* Register Network device */ if ( ( err = register_netdev ( netdev ) ) != 0 ) { DBGP ( "- %s ( ): register_netdev Failed\n", __func__ ); - goto err_down_chip; + goto err_register_netdev; } /* Set Initial Link State */ @@ -2836,12 +2836,13 @@ static int bnxt_init_one ( struct pci_device *pci ) return 0; unregister_netdev ( netdev ); - -err_down_chip: +err_register_netdev: +err_up_init: + bnxt_free_hwrm_mem ( bp ); +err_alloc_hwrm: bnxt_down_pci ( bp ); netdev_nullify ( netdev ); netdev_put ( netdev ); - disable_pdev: pci_set_drvdata ( pci, NULL ); return err;