Intel-Wired-Lan Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Tony Nguyen <anthony.l.nguyen@intel.com>
To: intel-wired-lan@osuosl.org
Subject: [Intel-wired-lan] [PATCH S43 14/15] ice: Fix for memory leaks and modify ICE_FREE_CQ_BUFS
Date: Fri, 15 May 2020 17:36:43 -0700	[thread overview]
Message-ID: <20200516003644.4658-14-anthony.l.nguyen@intel.com> (raw)
In-Reply-To: <20200516003644.4658-1-anthony.l.nguyen@intel.com>

From: Surabhi Boob <surabhi.boob@intel.com>

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

Signed-off-by: Surabhi Boob <surabhi.boob@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
---
 drivers/net/ethernet/intel/ice/ice_controlq.c | 49 +++++++++++--------
 1 file changed, 28 insertions(+), 21 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice_controlq.c b/drivers/net/ethernet/intel/ice/ice_controlq.c
index 9a865962296d..62c2c1e621d2 100644
--- a/drivers/net/ethernet/intel/ice/ice_controlq.c
+++ b/drivers/net/ethernet/intel/ice/ice_controlq.c
@@ -199,7 +199,9 @@ ice_alloc_rq_bufs(struct ice_hw *hw, struct ice_ctl_q_info *cq)
 		cq->rq.r.rq_bi[i].pa = 0;
 		cq->rq.r.rq_bi[i].size = 0;
 	}
+	cq->rq.r.rq_bi = NULL;
 	devm_kfree(ice_hw_to_dev(hw), cq->rq.dma_head);
+	cq->rq.dma_head = NULL;
 
 	return ICE_ERR_NO_MEMORY;
 }
@@ -245,7 +247,9 @@ ice_alloc_sq_bufs(struct ice_hw *hw, struct ice_ctl_q_info *cq)
 		cq->sq.r.sq_bi[i].pa = 0;
 		cq->sq.r.sq_bi[i].size = 0;
 	}
+	cq->sq.r.sq_bi = NULL;
 	devm_kfree(ice_hw_to_dev(hw), cq->sq.dma_head);
+	cq->sq.dma_head = NULL;
 
 	return ICE_ERR_NO_MEMORY;
 }
@@ -304,6 +308,28 @@ ice_cfg_rq_regs(struct ice_hw *hw, struct ice_ctl_q_info *cq)
 	return 0;
 }
 
+#define ICE_FREE_CQ_BUFS(hw, qi, ring)					\
+do {									\
+	int i;								\
+	/* free descriptors */						\
+	if ((qi)->ring.r.ring##_bi)					\
+		for (i = 0; i < (qi)->num_##ring##_entries; i++)	\
+			if ((qi)->ring.r.ring##_bi[i].pa) {		\
+				dmam_free_coherent(ice_hw_to_dev(hw),	\
+					(qi)->ring.r.ring##_bi[i].size,	\
+					(qi)->ring.r.ring##_bi[i].va,	\
+					(qi)->ring.r.ring##_bi[i].pa);	\
+					(qi)->ring.r.ring##_bi[i].va = NULL;\
+					(qi)->ring.r.ring##_bi[i].pa = 0;\
+					(qi)->ring.r.ring##_bi[i].size = 0;\
+		}							\
+	/* free the buffer info list */					\
+	if ((qi)->ring.cmd_buf)						\
+		devm_kfree(ice_hw_to_dev(hw), (qi)->ring.cmd_buf);	\
+	/* free DMA head */						\
+	devm_kfree(ice_hw_to_dev(hw), (qi)->ring.dma_head);		\
+} while (0)
+
 /**
  * ice_init_sq - main initialization routine for Control ATQ
  * @hw: pointer to the hardware structure
@@ -357,6 +383,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:
@@ -416,33 +443,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) {			\
-			dmam_free_coherent(ice_hw_to_dev(hw),		\
-					   (qi)->ring.r.ring##_bi[i].size,\
-					   (qi)->ring.r.ring##_bi[i].va,\
-					   (qi)->ring.r.ring##_bi[i].pa);\
-			(qi)->ring.r.ring##_bi[i].va = NULL;		\
-			(qi)->ring.r.ring##_bi[i].pa = 0;		\
-			(qi)->ring.r.ring##_bi[i].size = 0;		\
-		}							\
-	/* free the buffer info list */					\
-	if ((qi)->ring.cmd_buf)						\
-		devm_kfree(ice_hw_to_dev(hw), (qi)->ring.cmd_buf);	\
-	/* free DMA head */						\
-	devm_kfree(ice_hw_to_dev(hw), (qi)->ring.dma_head);		\
-} while (0)
-
 /**
  * ice_shutdown_sq - shutdown the Control ATQ
  * @hw: pointer to the hardware structure
-- 
2.20.1


  parent reply	other threads:[~2020-05-16  0:36 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-16  0:36 [Intel-wired-lan] [PATCH S43 01/15] ice: Call ice_aq_set_mac_cfg Tony Nguyen
2020-05-16  0:36 ` [Intel-wired-lan] [PATCH S43 02/15] ice: print Rx MDD auto reset message before VF reset Tony Nguyen
2020-05-22 19:27   ` Bowers, AndrewX
2020-05-16  0:36 ` [Intel-wired-lan] [PATCH S43 03/15] ice: Fix Tx timeout when link is toggled on a VF's interface Tony Nguyen
2020-05-22 19:30   ` Bowers, AndrewX
2020-05-16  0:36 ` [Intel-wired-lan] [PATCH S43 04/15] ice: Check if unicast MAC exists before setting VF MAC Tony Nguyen
2020-05-22 19:30   ` Bowers, AndrewX
2020-05-16  0:36 ` [Intel-wired-lan] [PATCH S43 05/15] ice: check for compatibility between DDP package and firmware Tony Nguyen
2020-05-22 19:31   ` Bowers, AndrewX
2020-05-16  0:36 ` [Intel-wired-lan] [PATCH S43 06/15] ice: Fix bad register reads Tony Nguyen
2020-05-22 19:56   ` Bowers, AndrewX
2020-05-16  0:36 ` [Intel-wired-lan] [PATCH S43 07/15] ice: fix usage of incorrect variable Tony Nguyen
2020-05-22 19:58   ` Bowers, AndrewX
2020-05-16  0:36 ` [Intel-wired-lan] [PATCH S43 08/15] ice: cleanup unsigned loops Tony Nguyen
2020-05-22 19:58   ` Bowers, AndrewX
2020-05-16  0:36 ` [Intel-wired-lan] [PATCH S43 09/15] ice: fix signed vs unsigned comparisons Tony Nguyen
2020-05-22 19:58   ` Bowers, AndrewX
2020-05-16  0:36 ` [Intel-wired-lan] [PATCH S43 10/15] ice: remove unused macro Tony Nguyen
2020-05-22 20:06   ` Bowers, AndrewX
2020-05-16  0:36 ` [Intel-wired-lan] [PATCH S43 11/15] ice: set VF default LAN address Tony Nguyen
2020-05-22 20:07   ` Bowers, AndrewX
2020-05-16  0:36 ` [Intel-wired-lan] [PATCH S43 12/15] ice: fix MAC write command Tony Nguyen
2020-05-22 20:07   ` Bowers, AndrewX
2020-05-16  0:36 ` [Intel-wired-lan] [PATCH S43 13/15] ice: Fix memory leak Tony Nguyen
2020-05-22 20:08   ` Bowers, AndrewX
2020-05-16  0:36 ` Tony Nguyen [this message]
2020-05-22 20:09   ` [Intel-wired-lan] [PATCH S43 14/15] ice: Fix for memory leaks and modify ICE_FREE_CQ_BUFS Bowers, AndrewX
2020-05-16  0:36 ` [Intel-wired-lan] [PATCH S43 15/15] ice: Add more Rx errors to netdev's rx_error counter Tony Nguyen
2020-05-22 20:09   ` Bowers, AndrewX
2020-05-22 19:14 ` [Intel-wired-lan] [PATCH S43 01/15] ice: Call ice_aq_set_mac_cfg Bowers, AndrewX

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=20200516003644.4658-14-anthony.l.nguyen@intel.com \
    --to=anthony.l.nguyen@intel.com \
    --cc=intel-wired-lan@osuosl.org \
    /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