linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] bnx2x: avoid leaking memory on bnx2x_init_one() failures
@ 2016-05-30 13:00 Vitaly Kuznetsov
  2016-05-31  6:46 ` Yuval Mintz
  2016-05-31 21:11 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Vitaly Kuznetsov @ 2016-05-30 13:00 UTC (permalink / raw)
  To: netdev; +Cc: linux-kernel, Ariel Elior

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 <vkuznets@redhat.com>
---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index 0a5b770..c5fe9158 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -13941,14 +13941,14 @@ static int bnx2x_init_one(struct pci_dev *pdev,
 		bp->doorbells = bnx2x_vf_doorbells(bp);
 		rc = bnx2x_vf_pci_alloc(bp);
 		if (rc)
-			goto init_one_exit;
+			goto init_one_freemem;
 	} else {
 		doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
 		if (doorbell_size > pci_resource_len(pdev, 2)) {
 			dev_err(&bp->pdev->dev,
 				"Cannot map doorbells, bar size too small, aborting\n");
 			rc = -ENOMEM;
-			goto init_one_exit;
+			goto init_one_freemem;
 		}
 		bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
 						doorbell_size);
@@ -13957,19 +13957,19 @@ 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_exit;
+		goto init_one_freemem;
 	}
 
 	if (IS_VF(bp)) {
 		rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
 		if (rc)
-			goto init_one_exit;
+			goto init_one_freemem;
 	}
 
 	/* 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_exit;
+		goto init_one_freemem;
 
 	/* calc qm_cid_count */
 	bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
@@ -13988,7 +13988,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_exit;
+		goto init_one_freemem;
 	}
 	BNX2X_DEV_INFO("set interrupts successfully\n");
 
@@ -13996,7 +13996,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_exit;
+		goto init_one_freemem;
 	}
 	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,
 
 	return 0;
 
+init_one_freemem:
+	bnx2x_free_mem_bp(bp);
+
 init_one_exit:
 	bnx2x_disable_pcie_error_reporting(bp);
 
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [PATCH net] bnx2x: avoid leaking memory on bnx2x_init_one() failures
  2016-05-30 13:00 [PATCH net] bnx2x: avoid leaking memory on bnx2x_init_one() failures Vitaly Kuznetsov
@ 2016-05-31  6:46 ` Yuval Mintz
  2016-05-31 21:11 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Yuval Mintz @ 2016-05-31  6:46 UTC (permalink / raw)
  To: Vitaly Kuznetsov, netdev; +Cc: linux-kernel, Ariel Elior

> 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 <vkuznets@redhat.com>

Thanks.

Acked-by: Yuval Mintz <Yuval.Mintz@qlogic.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] bnx2x: avoid leaking memory on bnx2x_init_one() failures
  2016-05-30 13:00 [PATCH net] bnx2x: avoid leaking memory on bnx2x_init_one() failures Vitaly Kuznetsov
  2016-05-31  6:46 ` Yuval Mintz
@ 2016-05-31 21:11 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2016-05-31 21:11 UTC (permalink / raw)
  To: vkuznets; +Cc: netdev, linux-kernel, ariel.elior

From: Vitaly Kuznetsov <vkuznets@redhat.com>
Date: Mon, 30 May 2016 15:00:54 +0200

> 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 <vkuznets@redhat.com>

Applied.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-05-31 21:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-30 13:00 [PATCH net] bnx2x: avoid leaking memory on bnx2x_init_one() failures Vitaly Kuznetsov
2016-05-31  6:46 ` Yuval Mintz
2016-05-31 21:11 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).