bnxt_en: Fix auxiliary device leak on early probe failures
PATCH 1/1 bnxt_en: Fix auxiliary device leak on early probe failures
bnxt_init_one() allocates the auxiliary device ID and initializes the auxiliary devices before bnxt_set_dflt_rings(). If that call, bnxt_init_int_mode() or the bnxt_pf_wq allocation fails, probe jumps to init_err_pci_clean, which does not uninitialize the devices or free the ID. Only init_err_cleanup does. The devices are never released, so their aux_priv, edev and ulp_tbl allocations and the ID in bnxt_aux_dev_ids are leaked once free_netdev() frees bp. A VF probed while the PF is down fails this way each time.
Add an init_err_auxdev label for this cleanup and use it for every failure after the devices are initialized. On the register_netdev() failure path the cleanup now runs after bnxt_clear_int_mode(), in the reverse order of setup.
---
Found with a static analysis tool we are developing.
Compile-tested only, with x86_64_defconfig plus BNXT and W=1.
drivers/net/ethernet/broadcom/bnxt/bnxt.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +6 -5
@@ -17423,7 +17423,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)netdev_err (bp->dev,"Not enough rings available.\n" ); rc = -ENOMEM ; } - goto init_err_pci_clean; + goto init_err_auxdev; }bnxt_fw_init_one_p3 (bp);
@@ -17435,7 +17435,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) rc =bnxt_init_int_mode (bp);if (rc) - goto init_err_pci_clean; + goto init_err_auxdev;/* No TC has been set yet and rings may have been trimmed due to * limited MSIX, so we re-initialize the TX rings per TC.
@@ -17449,7 +17449,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)if (!bnxt_pf_wq) {dev_err (&pdev->dev,"Unable to create workqueue.\n" ); rc = -ENOMEM ; - goto init_err_pci_clean; + goto init_err_auxdev; } } rc =bnxt_init_tc (bp);
@@ -17487,12 +17487,13 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)return 0 ; init_err_cleanup: -bnxt_aux_devices_uninit (bp); -bnxt_auxdev_id_free (bp, bp->auxdev_id);bnxt_dl_unregister (bp); init_err_dl:bnxt_shutdown_tc (bp);bnxt_clear_int_mode (bp); +init_err_auxdev: +bnxt_aux_devices_uninit (bp); +bnxt_auxdev_id_free (bp, bp->auxdev_id); init_err_pci_clean:bnxt_hwrm_func_drv_unrgtr (bp);
base-commit: 2a324a58a084c5cfd7e5a2f55e0786bee170a4a5
Signature · 1 line
2.43.0
Quoted 16 lines · Changyul Lee
bnxt_init_one()allocates the auxiliary device ID and initializes the auxiliary devices beforebnxt_set_dflt_rings(). If that call,bnxt_init_int_mode()or thebnxt_pf_wqallocation fails, probe jumps toinit_err_pci_clean, which does not uninitialize the devices or free the ID. Onlyinit_err_cleanupdoes. The devices are never released, so theiraux_priv, edev andulp_tblallocations and the ID inbnxt_aux_dev_idsare leaked oncefree_netdev()frees bp. A VF probed while the PF is down fails this way each time.Add an
init_err_auxdevlabel for this cleanup and use it for every failure after the devices are initialized. On theregister_netdev()failure path the cleanup now runs afterbnxt_clear_int_mode(), in the reverse order of setup.Fixes 2e4592dc9bee ("bnxt_en: Change MSIX/NQs allocation policy")Signed-off-by Changyul Lee <[email protected]>
Quoted 7 lines
---
Found with a static analysis tool we are developing.Compile-tested only, with
x86_64_defconfigplus BNXT and W=1.drivers/net/ethernet/broadcom/bnxt/bnxt.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] In bnxt_init_one() (drivers/net/ethernet/broadcom/bnxt/bnxt.c), a bnxt_pf_wq allocation…
- [Medium] bnxt_en: skipped bnxt_clear_int_mode() on bnxt_pf_wq error in bnxt_init_one()
- [Low] The commit message lists the leaking failure points as bnxt_set_dflt_rings(), bnxt_init_int_mode() and the bnxt_pf_wq…
--
bnxt_en: Fix auxiliary device leak on early probe failures
This patch adds an init_err_auxdev label to bnxt_init_one(). Failures after bnxt_aux_devices_init() now uninitialize the auxiliary devices and free the auxdev ID. The bnxt_set_dflt_rings(), bnxt_init_int_mode() and bnxt_pf_wq failure paths jump to the new label. On the register_netdev() failure path, the aux cleanup now runs after bnxt_clear_int_mode().
Quoted 5 lines
bnxt_init_one()allocates the auxiliary device ID and initializes the auxiliary devices beforebnxt_set_dflt_rings(). If that call,bnxt_init_int_mode()or thebnxt_pf_wqallocation fails, probe jumps toinit_err_pci_clean, which does not uninitialize the devices or free the ID. Onlyinit_err_cleanupdoes.
[Severity: Low]
This list leaves out one path whose behaviour the patch also changes:
the bnxt_dl_register() failure that jumps to init_err_dl.
Before the patch, init_err_dl ran bnxt_shutdown_tc() and bnxt_clear_int_mode() and then fell straight into init_err_pci_clean. That skipped bnxt_aux_devices_uninit() and bnxt_auxdev_id_free(), so aux_priv, edev, ulp_tbl and the bnxt_aux_dev_ids entry leaked on that path too.
Now init_err_dl falls through into init_err_auxdev, so that path gets the aux cleanup. The code change is fine. Could the commit message name this path as well, so the scope is clear to backporters?
Quoted 4 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0
-0
[ ... ]
drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) · line 17452
Quoted 6 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1
-1@@ -17449,7 +17449,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)if (!bnxt_pf_wq) {dev_err (&pdev->dev,"Unable to create workqueue.\n" ); rc = -ENOMEM ; - goto init_err_pci_clean; + goto init_err_auxdev;
[Severity: Medium]
Does this path still leak the MSI-X vectors and bp->irq_tbl?
By the time create_singlethread_workqueue() runs, bnxt_init_int_mode() has already succeeded. It has allocated the MSI-X vectors with pci_alloc_irq_vectors() and allocated bp->irq_tbl. The new init_err_auxdev label sits below bnxt_clear_int_mode() under init_err_dl, so jumping to it skips the only call that releases them. Nothing under init_err_pci_clean or init_err_free calls pci_free_irq_vectors() or frees the table either. bnxt_cleanup_pci() only unmaps the BARs, releases the regions and disables the device.
This can happen on the first PF probe, while bnxt_pf_wq is still NULL, if the workqueue allocation fails. Once free_netdev() frees bp, the irq_tbl pointer is lost. The vectors also stay allocated on bp->pdev with msix_enabled still set. A later probe of the same function would then trip the msix_enabled WARN_ON_ONCE() in __pci_enable_msix_range() and fail to set up interrupts.
The old init_err_pci_clean target had the same gap. The commit message says the unwind now follows the reverse order of setup, so should this goto jump to init_err_dl instead?
At that point bp->tc_info is still NULL, so bnxt_shutdown_tc() returns early. bnxt_clear_int_mode() then frees the vectors and irq_tbl, and execution falls through into the new aux cleanup.
[Severity: Medium]
Does this path still leak the MSI-X vectors and bp->irq_tbl?
By this point bnxt_init_int_mode() has already succeeded. It has called pci_alloc_irq_vectors() and allocated bp->irq_tbl. The new label sits below bnxt_clear_int_mode():
init_err_dl:
bnxt_shutdown_tc(bp); bnxt_clear_int_mode(bp); init_err_auxdev: bnxt_aux_devices_uninit(bp); bnxt_auxdev_id_free(bp, bp->auxdev_id);
Nothing under init_err_pci_clean frees the vectors or the table either. bnxt_cleanup_pci() only disables PTM, unmaps the BARs, releases the regions and disables the device.
This can happen on the first PF probe, while bnxt_pf_wq is still NULL, if create_singlethread_workqueue() fails. After free_netdev() the irq_tbl pointer is lost and pdev->msix_enabled stays set. msi_device_data_release() would then hit its WARN_ON_ONCE(!xa_empty(...)) on devres release. A later probe of the same function would also fail in __pci_enable_msix_range():
if (WARN_ON_ONCE(dev->msix_enabled)) return -EINVAL;
The old init_err_pci_clean target had the same gap. Since this goto is being rewritten to unwind in reverse order of setup, should it jump to init_err_dl instead?
At that point bnxt_shutdown_tc() is a no-op because bp->tc_info is still NULL. bnxt_clear_int_mode() would release the vectors and irq_tbl, and execution would then fall through into the new aux cleanup.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118050716.3873167-1-lcy8047%40gmail.com
Quoted 11 lines · On Fri, Nov 20, 2026 at 05:07:17AM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
Quoted 4 lines
- [Medium] In
bnxt_init_one()(drivers/net/ethernet/broadcom/bnxt/bnxt.c), abnxt_pf_wqallocation…
- [Medium]bnxt_en: skippedbnxt_clear_int_mode()onbnxt_pf_wqerror inbnxt_init_one()
The two issues above appear to be the same issue. It does seem to be a real leak, similar to the one addressed by the patch under review. Yet strictly speaking different.
I'm indifferent as to weather it's fixed in a revised version of this patch or as a follow-up.
Quoted 2 lines
- [Low] The commit message lists the leaking failure points as
bnxt_set_dflt_rings(),bnxt_init_int_mode()and the bnxt_pf_wq…
This does seem nice, but I don't think it warrants a respin by itself.