Commit bae5499c authored by Vitaly Kuznetsov's avatar Vitaly Kuznetsov Committed by David S. Miller

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: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
Acked-by: default avatarYuval Mintz <Yuval.Mintz@qlogic.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 95e4daa8
...@@ -13941,14 +13941,14 @@ static int bnx2x_init_one(struct pci_dev *pdev, ...@@ -13941,14 +13941,14 @@ static int bnx2x_init_one(struct pci_dev *pdev,
bp->doorbells = bnx2x_vf_doorbells(bp); bp->doorbells = bnx2x_vf_doorbells(bp);
rc = bnx2x_vf_pci_alloc(bp); rc = bnx2x_vf_pci_alloc(bp);
if (rc) if (rc)
goto init_one_exit; goto init_one_freemem;
} else { } else {
doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT); doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
if (doorbell_size > pci_resource_len(pdev, 2)) { if (doorbell_size > pci_resource_len(pdev, 2)) {
dev_err(&bp->pdev->dev, dev_err(&bp->pdev->dev,
"Cannot map doorbells, bar size too small, aborting\n"); "Cannot map doorbells, bar size too small, aborting\n");
rc = -ENOMEM; rc = -ENOMEM;
goto init_one_exit; goto init_one_freemem;
} }
bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2), bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
doorbell_size); doorbell_size);
...@@ -13957,19 +13957,19 @@ static int bnx2x_init_one(struct pci_dev *pdev, ...@@ -13957,19 +13957,19 @@ static int bnx2x_init_one(struct pci_dev *pdev,
dev_err(&bp->pdev->dev, dev_err(&bp->pdev->dev,
"Cannot map doorbell space, aborting\n"); "Cannot map doorbell space, aborting\n");
rc = -ENOMEM; rc = -ENOMEM;
goto init_one_exit; goto init_one_freemem;
} }
if (IS_VF(bp)) { if (IS_VF(bp)) {
rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count); rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
if (rc) if (rc)
goto init_one_exit; goto init_one_freemem;
} }
/* Enable SRIOV if capability found in configuration space */ /* Enable SRIOV if capability found in configuration space */
rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS); rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
if (rc) if (rc)
goto init_one_exit; goto init_one_freemem;
/* calc qm_cid_count */ /* calc qm_cid_count */
bp->qm_cid_count = bnx2x_set_qm_cid_count(bp); bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
...@@ -13988,7 +13988,7 @@ static int bnx2x_init_one(struct pci_dev *pdev, ...@@ -13988,7 +13988,7 @@ static int bnx2x_init_one(struct pci_dev *pdev,
rc = bnx2x_set_int_mode(bp); rc = bnx2x_set_int_mode(bp);
if (rc) { if (rc) {
dev_err(&pdev->dev, "Cannot set interrupts\n"); dev_err(&pdev->dev, "Cannot set interrupts\n");
goto init_one_exit; goto init_one_freemem;
} }
BNX2X_DEV_INFO("set interrupts successfully\n"); BNX2X_DEV_INFO("set interrupts successfully\n");
...@@ -13996,7 +13996,7 @@ static int bnx2x_init_one(struct pci_dev *pdev, ...@@ -13996,7 +13996,7 @@ static int bnx2x_init_one(struct pci_dev *pdev,
rc = register_netdev(dev); rc = register_netdev(dev);
if (rc) { if (rc) {
dev_err(&pdev->dev, "Cannot register net device\n"); dev_err(&pdev->dev, "Cannot register net device\n");
goto init_one_exit; goto init_one_freemem;
} }
BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name); BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
...@@ -14029,6 +14029,9 @@ static int bnx2x_init_one(struct pci_dev *pdev, ...@@ -14029,6 +14029,9 @@ static int bnx2x_init_one(struct pci_dev *pdev,
return 0; return 0;
init_one_freemem:
bnx2x_free_mem_bp(bp);
init_one_exit: init_one_exit:
bnx2x_disable_pcie_error_reporting(bp); bnx2x_disable_pcie_error_reporting(bp);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment