patches for DPDK stable branches
 help / color / mirror / Atom feed
From: wangyunjian <wangyunjian@huawei.com>
To: <dev@dpdk.org>
Cc: <qiming.yang@intel.com>, <qi.z.zhang@intel.com>,
	<jerry.lilijun@huawei.com>, <xudingke@huawei.com>,
	Yunjian Wang <wangyunjian@huawei.com>, <stable@dpdk.org>
Subject: [dpdk-stable] [dpdk-dev] [PATCH 2/2] net/ice: fix return value of null not checked
Date: Tue, 28 Jul 2020 21:11:27 +0800	[thread overview]
Message-ID: <2d36faa8a550dea466f87a9556db9f69c7cafe6b.1595936682.git.wangyunjian@huawei.com> (raw)
In-Reply-To: <cover.1595936682.git.wangyunjian@huawei.com>

From: Yunjian Wang <wangyunjian@huawei.com>

The function rte_zmalloc() could return NULL, the return
value need to be checked.

Fixes: 50370662b727 ("net/ice: support device and queue ops")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
 drivers/net/ice/ice_ethdev.c | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ice/ice_ethdev.c b/drivers/net/ice/ice_ethdev.c
index 5f3882826..643dfc6b5 100644
--- a/drivers/net/ice/ice_ethdev.c
+++ b/drivers/net/ice/ice_ethdev.c
@@ -2623,13 +2623,24 @@ static int ice_init_rss(struct ice_pf *pf)
 		return 0;
 	}
 
-	if (!vsi->rss_key)
+	if (!vsi->rss_key) {
 		vsi->rss_key = rte_zmalloc(NULL,
 					   vsi->rss_key_size, 0);
-	if (!vsi->rss_lut)
+		if (vsi->rss_key == NULL) {
+			PMD_DRV_LOG(ERR, "Failed to allocate memory for rss_key");
+			return -ENOMEM;
+		}
+	}
+	if (!vsi->rss_lut) {
 		vsi->rss_lut = rte_zmalloc(NULL,
 					   vsi->rss_lut_size, 0);
-
+		if (vsi->rss_lut == NULL) {
+			PMD_DRV_LOG(ERR, "Failed to allocate memory for rss_key");
+			rte_free(vsi->rss_key);
+			vsi->rss_key = NULL;
+			return -ENOMEM;
+		}
+	}
 	/* configure RSS key */
 	if (!rss_conf->rss_key) {
 		/* Calculate the default hash key */
@@ -2643,7 +2654,7 @@ static int ice_init_rss(struct ice_pf *pf)
 	rte_memcpy(key.standard_rss_key, vsi->rss_key, vsi->rss_key_size);
 	ret = ice_aq_set_rss_key(hw, vsi->idx, &key);
 	if (ret)
-		return -EINVAL;
+		goto out;
 
 	/* init RSS LUT table */
 	for (i = 0; i < vsi->rss_lut_size; i++)
@@ -2653,7 +2664,7 @@ static int ice_init_rss(struct ice_pf *pf)
 				 ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF,
 				 vsi->rss_lut, vsi->rss_lut_size);
 	if (ret)
-		return -EINVAL;
+		goto out;
 
 	/* Enable registers for symmetric_toeplitz function. */
 	reg = ICE_READ_REG(hw, VSIQF_HASH_CTL(vsi->vsi_id));
@@ -2665,6 +2676,12 @@ static int ice_init_rss(struct ice_pf *pf)
 	ice_rss_hash_set(pf, rss_conf->rss_hf);
 
 	return 0;
+out:
+	rte_free(vsi->rss_key);
+	vsi->rss_key = NULL;
+	rte_free(vsi->rss_lut);
+	vsi->rss_lut = NULL;
+	return -EINVAL;
 }
 
 static int
-- 
2.23.0



      parent reply	other threads:[~2020-07-28 13:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1595936682.git.wangyunjian@huawei.com>
2020-07-28 13:11 ` [dpdk-stable] [dpdk-dev] [PATCH 1/2] net/ice: fix memory leak when releasing vsi wangyunjian
2020-07-28 13:11 ` wangyunjian [this message]

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=2d36faa8a550dea466f87a9556db9f69c7cafe6b.1595936682.git.wangyunjian@huawei.com \
    --to=wangyunjian@huawei.com \
    --cc=dev@dpdk.org \
    --cc=jerry.lilijun@huawei.com \
    --cc=qi.z.zhang@intel.com \
    --cc=qiming.yang@intel.com \
    --cc=stable@dpdk.org \
    --cc=xudingke@huawei.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).