Skip to content

Commit bae5499

Browse files
vittyvkdavem330
authored andcommitted
bnx2x: avoid leaking memory on bnx2x_init_one() failures
bnx2x_init_bp() allocates memory with bnx2x_alloc_mem_bp() so if we fail later in bnx2x_init_one() we need to free this memory with bnx2x_free_mem_bp() to avoid leakages. E.g. I'm observing memory leaks reported by kmemleak when a failure (unrelated) happens in bnx2x_vfpf_acquire(). Signed-off-by: Vitaly Kuznetsov <[email protected]> Acked-by: Yuval Mintz <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 95e4daa commit bae5499

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13941,14 +13941,14 @@ static int bnx2x_init_one(struct pci_dev *pdev,
1394113941
bp->doorbells = bnx2x_vf_doorbells(bp);
1394213942
rc = bnx2x_vf_pci_alloc(bp);
1394313943
if (rc)
13944-
goto init_one_exit;
13944+
goto init_one_freemem;
1394513945
} else {
1394613946
doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
1394713947
if (doorbell_size > pci_resource_len(pdev, 2)) {
1394813948
dev_err(&bp->pdev->dev,
1394913949
"Cannot map doorbells, bar size too small, aborting\n");
1395013950
rc = -ENOMEM;
13951-
goto init_one_exit;
13951+
goto init_one_freemem;
1395213952
}
1395313953
bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
1395413954
doorbell_size);
@@ -13957,19 +13957,19 @@ static int bnx2x_init_one(struct pci_dev *pdev,
1395713957
dev_err(&bp->pdev->dev,
1395813958
"Cannot map doorbell space, aborting\n");
1395913959
rc = -ENOMEM;
13960-
goto init_one_exit;
13960+
goto init_one_freemem;
1396113961
}
1396213962

1396313963
if (IS_VF(bp)) {
1396413964
rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
1396513965
if (rc)
13966-
goto init_one_exit;
13966+
goto init_one_freemem;
1396713967
}
1396813968

1396913969
/* Enable SRIOV if capability found in configuration space */
1397013970
rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
1397113971
if (rc)
13972-
goto init_one_exit;
13972+
goto init_one_freemem;
1397313973

1397413974
/* calc qm_cid_count */
1397513975
bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
@@ -13988,15 +13988,15 @@ static int bnx2x_init_one(struct pci_dev *pdev,
1398813988
rc = bnx2x_set_int_mode(bp);
1398913989
if (rc) {
1399013990
dev_err(&pdev->dev, "Cannot set interrupts\n");
13991-
goto init_one_exit;
13991+
goto init_one_freemem;
1399213992
}
1399313993
BNX2X_DEV_INFO("set interrupts successfully\n");
1399413994

1399513995
/* register the net device */
1399613996
rc = register_netdev(dev);
1399713997
if (rc) {
1399813998
dev_err(&pdev->dev, "Cannot register net device\n");
13999-
goto init_one_exit;
13999+
goto init_one_freemem;
1400014000
}
1400114001
BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
1400214002

@@ -14029,6 +14029,9 @@ static int bnx2x_init_one(struct pci_dev *pdev,
1402914029

1403014030
return 0;
1403114031

14032+
init_one_freemem:
14033+
bnx2x_free_mem_bp(bp);
14034+
1403214035
init_one_exit:
1403314036
bnx2x_disable_pcie_error_reporting(bp);
1403414037

0 commit comments

Comments
 (0)