patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Qi Zhang <qi.z.zhang@intel.com>
To: ferruh.yigit@intel.com
Cc: xiaolong.ye@intel.com, qiming.yang@intel.com, dev@dpdk.org,
	Qi Zhang <qi.z.zhang@intel.com>,
	stable@dpdk.org, Surabhi Boob <surabhi.boob@intel.com>,
	"Paul M . Stillwell Jr" <paul.m.stillwell.jr@intel.com>
Subject: [dpdk-stable] [PATCH v3 37/53] net/ice/base: fix for memory leak
Date: Mon, 15 Jun 2020 10:04:59 +0800	[thread overview]
Message-ID: <20200615020515.1359-38-qi.z.zhang@intel.com> (raw)
In-Reply-To: <20200615020515.1359-1-qi.z.zhang@intel.com>

Handles memory leaks during control queue initialization and
buffer allocation failures. The MACRO - ICE_FREE_CQ_BUFS is modified to
re-use for this fix.

Fixes: 6c1f26be50a2 ("net/ice/base: add control queue information")
Cc: stable@dpdk.org

Signed-off-by: Surabhi Boob <surabhi.boob@intel.com>
Signed-off-by: Paul M. Stillwell Jr <paul.m.stillwell.jr@intel.com>
Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
---
 drivers/net/ice/base/ice_controlq.c | 39 +++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 15 deletions(-)

diff --git a/drivers/net/ice/base/ice_controlq.c b/drivers/net/ice/base/ice_controlq.c
index 3ef86fa03..f278ef636 100644
--- a/drivers/net/ice/base/ice_controlq.c
+++ b/drivers/net/ice/base/ice_controlq.c
@@ -182,7 +182,9 @@ ice_alloc_rq_bufs(struct ice_hw *hw, struct ice_ctl_q_info *cq)
 	i--;
 	for (; i >= 0; i--)
 		ice_free_dma_mem(hw, &cq->rq.r.rq_bi[i]);
+	cq->rq.r.rq_bi = NULL;
 	ice_free(hw, cq->rq.dma_head);
+	cq->rq.dma_head = NULL;
 
 	return ICE_ERR_NO_MEMORY;
 }
@@ -220,7 +222,9 @@ ice_alloc_sq_bufs(struct ice_hw *hw, struct ice_ctl_q_info *cq)
 	i--;
 	for (; i >= 0; i--)
 		ice_free_dma_mem(hw, &cq->sq.r.sq_bi[i]);
+	cq->sq.r.sq_bi = NULL;
 	ice_free(hw, cq->sq.dma_head);
+	cq->sq.dma_head = NULL;
 
 	return ICE_ERR_NO_MEMORY;
 }
@@ -279,6 +283,24 @@ ice_cfg_rq_regs(struct ice_hw *hw, struct ice_ctl_q_info *cq)
 	return ICE_SUCCESS;
 }
 
+#define ICE_FREE_CQ_BUFS(hw, qi, ring)					\
+do {									\
+	/* free descriptors */						\
+	if ((qi)->ring.r.ring##_bi) {					\
+		int i;							\
+									\
+		for (i = 0; i < (qi)->num_##ring##_entries; i++)	\
+			if ((qi)->ring.r.ring##_bi[i].pa)		\
+				ice_free_dma_mem((hw),			\
+					&(qi)->ring.r.ring##_bi[i]);	\
+	}								\
+	/* free the buffer info list */					\
+	if ((qi)->ring.cmd_buf)						\
+		ice_free(hw, (qi)->ring.cmd_buf);			\
+	/* free DMA head */						\
+	ice_free(hw, (qi)->ring.dma_head);				\
+} while (0)
+
 /**
  * ice_init_sq - main initialization routine for Control ATQ
  * @hw: pointer to the hardware structure
@@ -334,6 +356,7 @@ static enum ice_status ice_init_sq(struct ice_hw *hw, struct ice_ctl_q_info *cq)
 	goto init_ctrlq_exit;
 
 init_ctrlq_free_rings:
+	ICE_FREE_CQ_BUFS(hw, cq, sq);
 	ice_free_cq_ring(hw, &cq->sq);
 
 init_ctrlq_exit:
@@ -395,27 +418,13 @@ static enum ice_status ice_init_rq(struct ice_hw *hw, struct ice_ctl_q_info *cq)
 	goto init_ctrlq_exit;
 
 init_ctrlq_free_rings:
+	ICE_FREE_CQ_BUFS(hw, cq, rq);
 	ice_free_cq_ring(hw, &cq->rq);
 
 init_ctrlq_exit:
 	return ret_code;
 }
 
-#define ICE_FREE_CQ_BUFS(hw, qi, ring)					\
-do {									\
-	int i;								\
-	/* free descriptors */						\
-	for (i = 0; i < (qi)->num_##ring##_entries; i++)		\
-		if ((qi)->ring.r.ring##_bi[i].pa)			\
-			ice_free_dma_mem((hw),				\
-					 &(qi)->ring.r.ring##_bi[i]);	\
-	/* free the buffer info list */					\
-	if ((qi)->ring.cmd_buf)						\
-		ice_free(hw, (qi)->ring.cmd_buf);			\
-	/* free DMA head */						\
-	ice_free(hw, (qi)->ring.dma_head);				\
-} while (0)
-
 /**
  * ice_shutdown_sq - shutdown the Control ATQ
  * @hw: pointer to the hardware structure
-- 
2.13.6


  parent reply	other threads:[~2020-06-15  2:03 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200603024016.30636-1-qi.z.zhang@intel.com>
2020-06-03  2:39 ` [dpdk-stable] [PATCH 10/52] net/ice/base: fix variable type for ACL Qi Zhang
2020-06-03  2:40 ` [dpdk-stable] [PATCH 37/52] net/ice/base: fix for memory leak Qi Zhang
2020-06-03  2:40 ` [dpdk-stable] [PATCH 47/52] net/ice/base: fix reference count when update VSI list Qi Zhang
2020-06-03  2:40 ` [dpdk-stable] [PATCH 49/52] net/ice/base: fix uninitialized flag Qi Zhang
2020-06-08  2:51   ` Yang, Qiming
     [not found] ` <20200609120001.35110-1-qi.z.zhang@intel.com>
2020-06-09 11:59   ` [dpdk-stable] [PATCH v2 10/52] net/ice/base: fix variable type for ACL Qi Zhang
2020-06-11 18:35     ` [dpdk-stable] [dpdk-dev] " Ferruh Yigit
2020-06-09 11:59   ` [dpdk-stable] [PATCH v2 37/52] net/ice/base: fix for memory leak Qi Zhang
2020-06-09 11:59   ` [dpdk-stable] [PATCH v2 47/52] net/ice/base: fix reference count when update VSI list Qi Zhang
2020-06-09 11:59   ` [dpdk-stable] [PATCH v2 49/52] net/ice/base: fix uninitialized flag Qi Zhang
2020-06-11 18:45     ` Ferruh Yigit
     [not found] ` <20200615015342.1191-1-qi.z.zhang@intel.com>
2020-06-15  1:52   ` [dpdk-stable] [PATCH v3 10/53] net/ice/base: fix variable type for ACL Qi Zhang
2020-06-15  1:53   ` [dpdk-stable] [PATCH v3 35/53] net/ice/base: fix return value Qi Zhang
2020-06-15  1:53   ` [dpdk-stable] [PATCH v3 37/53] net/ice/base: fix for memory leak Qi Zhang
2020-06-15  1:53   ` [dpdk-stable] [PATCH v3 47/53] net/ice/base: fix reference count when update VSI list Qi Zhang
2020-06-15  1:53   ` [dpdk-stable] [PATCH v3 49/53] net/ice/base: fix uninitialized flag for result index bitmap Qi Zhang
     [not found] ` <20200615020515.1359-1-qi.z.zhang@intel.com>
2020-06-15  2:04   ` [dpdk-stable] [PATCH v3 10/53] net/ice/base: fix variable type for ACL Qi Zhang
2020-06-15  2:04   ` [dpdk-stable] [PATCH v3 35/53] net/ice/base: fix return value Qi Zhang
2020-06-15  2:04   ` Qi Zhang [this message]
2020-06-15  2:05   ` [dpdk-stable] [PATCH v3 47/53] net/ice/base: fix reference count when update VSI list Qi Zhang
2020-06-15  2:05   ` [dpdk-stable] [PATCH v3 49/53] net/ice/base: fix uninitialized flag for result index bitmap Qi Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200615020515.1359-38-qi.z.zhang@intel.com \
    --to=qi.z.zhang@intel.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=paul.m.stillwell.jr@intel.com \
    --cc=qiming.yang@intel.com \
    --cc=stable@dpdk.org \
    --cc=surabhi.boob@intel.com \
    --cc=xiaolong.ye@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).