* [PATCH v2] bnx2x: fix resource leaks in bnx2x_init_one() error paths
@ 2026-06-09 7:46 Haoxiang Li
2026-06-11 15:32 ` Simon Horman
0 siblings, 1 reply; 2+ messages in thread
From: Haoxiang Li @ 2026-06-09 7:46 UTC (permalink / raw)
To: skalluru, manishc, andrew+netdev, davem, edumazet, kuba, pabeni,
ariele
Cc: netdev, linux-kernel, Haoxiang Li, stable
bnx2x_init_one() falls through to the common memory cleanup path for
several failures after probe has already acquired additional resources.
If register_netdev() fails after bnx2x_set_int_mode(), MSI/MSI-X remains
enabled. If later failures happen after bnx2x_iov_init_one(), PF SR-IOV
state can be left allocated. Also, failures after bnx2x_vfpf_acquire()
must release the PF resources before freeing the VF-PF mailbox allocated
by bnx2x_vf_pci_alloc().
Add error labels matching the resource acquisition order so probe failure
disables MSI/MSI-X, removes SR-IOV state, releases VF-PF resources,
deallocates VF PCI resources, and then frees the common driver memory.
Also clear PCI drvdata before freeing the netdev on probe failure.
Fixes: 6411280ac94d ("bnx2x: Segregate SR-IOV code")
Cc: stable@vger.kernel.org
Signed-off-by: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
---
Changes in v2:
- Unwind all resources acquired by bnx2x_init_one() on failure
- Clear PCI drvdata before freeing the netdev on probe failure.
- Modify the commit title and message.
---
.../net/ethernet/broadcom/bnx2x/bnx2x_main.c | 26 +++++++++++++++----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index da0f8c353e6a..f44ff9e7062b 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -13893,6 +13893,7 @@ static int bnx2x_init_one(struct pci_dev *pdev,
rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
if (rc < 0) {
+ pci_set_drvdata(pdev, NULL);
free_netdev(dev);
return rc;
}
@@ -13932,13 +13933,13 @@ static int bnx2x_init_one(struct pci_dev *pdev,
dev_err(&bp->pdev->dev,
"Cannot map doorbell space, aborting\n");
rc = -ENOMEM;
- goto init_one_freemem;
+ goto init_one_vf_pci_dealloc;
}
if (IS_VF(bp)) {
rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
if (rc)
- goto init_one_freemem;
+ goto init_one_vf_pci_dealloc;
#ifdef CONFIG_BNX2X_SRIOV
/* VF with OLD Hypervisor or old PF do not support filtering */
@@ -13952,7 +13953,7 @@ static int bnx2x_init_one(struct pci_dev *pdev,
/* Enable SRIOV if capability found in configuration space */
rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
if (rc)
- goto init_one_freemem;
+ goto init_one_vfpf_release;
/* calc qm_cid_count */
bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
@@ -13971,7 +13972,7 @@ static int bnx2x_init_one(struct pci_dev *pdev,
rc = bnx2x_set_int_mode(bp);
if (rc) {
dev_err(&pdev->dev, "Cannot set interrupts\n");
- goto init_one_freemem;
+ goto init_one_iov_remove;
}
BNX2X_DEV_INFO("set interrupts successfully\n");
@@ -13979,7 +13980,7 @@ static int bnx2x_init_one(struct pci_dev *pdev,
rc = register_netdev(dev);
if (rc) {
dev_err(&pdev->dev, "Cannot register net device\n");
- goto init_one_freemem;
+ goto init_one_disable_msi;
}
BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
@@ -14001,6 +14002,20 @@ static int bnx2x_init_one(struct pci_dev *pdev,
return 0;
+init_one_disable_msi:
+ bnx2x_disable_msi(bp);
+
+init_one_iov_remove:
+ bnx2x_iov_remove_one(bp);
+
+init_one_vfpf_release:
+ if (IS_VF(bp))
+ bnx2x_vfpf_release(bp);
+
+init_one_vf_pci_dealloc:
+ if (IS_VF(bp))
+ bnx2x_vf_pci_dealloc(bp);
+
init_one_freemem:
bnx2x_free_mem_bp(bp);
@@ -14011,6 +14026,7 @@ static int bnx2x_init_one(struct pci_dev *pdev,
if (IS_PF(bp) && bp->doorbells)
iounmap(bp->doorbells);
+ pci_set_drvdata(pdev, NULL);
free_netdev(dev);
if (atomic_read(&pdev->enable_cnt) == 1)
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] bnx2x: fix resource leaks in bnx2x_init_one() error paths
2026-06-09 7:46 [PATCH v2] bnx2x: fix resource leaks in bnx2x_init_one() error paths Haoxiang Li
@ 2026-06-11 15:32 ` Simon Horman
0 siblings, 0 replies; 2+ messages in thread
From: Simon Horman @ 2026-06-11 15:32 UTC (permalink / raw)
To: Haoxiang Li
Cc: skalluru, manishc, andrew+netdev, davem, edumazet, kuba, pabeni,
ariele, netdev, linux-kernel, stable
On Tue, Jun 09, 2026 at 03:46:10PM +0800, Haoxiang Li wrote:
> bnx2x_init_one() falls through to the common memory cleanup path for
> several failures after probe has already acquired additional resources.
>
> If register_netdev() fails after bnx2x_set_int_mode(), MSI/MSI-X remains
> enabled. If later failures happen after bnx2x_iov_init_one(), PF SR-IOV
> state can be left allocated. Also, failures after bnx2x_vfpf_acquire()
> must release the PF resources before freeing the VF-PF mailbox allocated
> by bnx2x_vf_pci_alloc().
>
> Add error labels matching the resource acquisition order so probe failure
> disables MSI/MSI-X, removes SR-IOV state, releases VF-PF resources,
> deallocates VF PCI resources, and then frees the common driver memory.
> Also clear PCI drvdata before freeing the netdev on probe failure.
>
> Fixes: 6411280ac94d ("bnx2x: Segregate SR-IOV code")
> Cc: stable@vger.kernel.org
> Signed-off-by: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
> ---
> Changes in v2:
> - Unwind all resources acquired by bnx2x_init_one() on failure
> - Clear PCI drvdata before freeing the netdev on probe failure.
> - Modify the commit title and message.
Reviewed-by: Simon Horman <horms@kernel.org>
FTR, there is an AI-generated review of this patch available on sashiko.dev.
However, I believe the issue flagged there can be looked at in the context
of possible follow-up and should not impede the progress of this patch.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-11 15:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-09 7:46 [PATCH v2] bnx2x: fix resource leaks in bnx2x_init_one() error paths Haoxiang Li
2026-06-11 15:32 ` Simon Horman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox