[dpdk-dev] [PATCH] lib/librte_ip_frag:fix ip frag process log

Li Han han.li1 at zte.com.cn
Wed Apr 18 10:37:22 CEST 2018


in ip_frag_process,some IP_FRAG_LOG content is wrong

Signed-off-by: Li Han <han.li1 at zte.com.cn>
---
 lib/librte_ip_frag/ip_frag_internal.c              |  10 +-
 ...40e-add-null-point-check-and-fix-mem-leak.patch | 150 +++++++++++++++++++
 ...1000-add-null-point-check-for-rte_zmalloc.patch |  65 ++++++++
 ...qat-add-null-point-check-and-fix-mem-leak.patch |  84 +++++++++++
 ...qat-add-null-point-check-and-fix-mem-leak.patch |  92 ++++++++++++
 ...1000-add-null-point-check-for-rte_zmalloc.patch |  77 ++++++++++
 ...40e-add-null-point-check-and-fix-mem-leak.patch | 163 +++++++++++++++++++++
 7 files changed, 636 insertions(+), 5 deletions(-)
 create mode 100644 v3-0001-net-i40e-add-null-point-check-and-fix-mem-leak.patch
 create mode 100644 v3-0002-net-e1000-add-null-point-check-for-rte_zmalloc.patch
 create mode 100644 v3-0003-crypto-qat-add-null-point-check-and-fix-mem-leak.patch
 create mode 100644 v4-0001-crypto-qat-add-null-point-check-and-fix-mem-leak.patch
 create mode 100644 v4-0001-net-e1000-add-null-point-check-for-rte_zmalloc.patch
 create mode 100644 v4-0001-net-i40e-add-null-point-check-and-fix-mem-leak.patch

diff --git a/lib/librte_ip_frag/ip_frag_internal.c b/lib/librte_ip_frag/ip_frag_internal.c
index 7397aa6..7db5bc6 100644
--- a/lib/librte_ip_frag/ip_frag_internal.c
+++ b/lib/librte_ip_frag/ip_frag_internal.c
@@ -152,9 +152,9 @@ struct rte_mbuf *
 				fp->frags[IP_LAST_FRAG_IDX].len);
 		else
 			IP_FRAG_LOG(DEBUG, "%s:%d invalid fragmented packet:\n"
-				"ipv4_frag_pkt: %p, key: <" IPv6_KEY_BYTES_FMT ", %#x>, "
+				"ipv6_frag_pkt: %p, key: <" IPv6_KEY_BYTES_FMT ", %#x>, "
 				"total_size: %u, frag_size: %u, last_idx: %u\n"
-				"first fragment: ofs: %u, len: %u\n"
+		i		"first fragment: ofs: %u, len: %u\n"
 				"last fragment: ofs: %u, len: %u\n\n",
 				__func__, __LINE__,
 				fp, IPv6_KEY_BYTES(fp->key.src_dst), fp->key.id,
@@ -210,7 +210,7 @@ struct rte_mbuf *
 				fp->frags[IP_LAST_FRAG_IDX].len);
 		else
 			IP_FRAG_LOG(DEBUG, "%s:%d invalid fragmented packet:\n"
-				"ipv4_frag_pkt: %p, key: <" IPv6_KEY_BYTES_FMT ", %#x>, "
+				"ipv6_frag_pkt: %p, key: <" IPv6_KEY_BYTES_FMT ", %#x>, "
 				"total_size: %u, frag_size: %u, last_idx: %u\n"
 				"first fragment: ofs: %u, len: %u\n"
 				"last fragment: ofs: %u, len: %u\n\n",
@@ -331,7 +331,7 @@ struct ip_frag_pkt *
 		if (p1->key.key_len == IPV4_KEYLEN)
 			IP_FRAG_LOG(DEBUG, "%s:%d:\n"
 					"tbl: %p, max_entries: %u, use_entries: %u\n"
-					"ipv6_frag_pkt line0: %p, index: %u from %u\n"
+					"ipv4_frag_pkt line0: %p, index: %u from %u\n"
 			"key: <%" PRIx64 ", %#x>, start: %" PRIu64 "\n",
 					__func__, __LINE__,
 					tbl, tbl->max_entries, tbl->use_entries,
@@ -357,7 +357,7 @@ struct ip_frag_pkt *
 		if (p2->key.key_len == IPV4_KEYLEN)
 			IP_FRAG_LOG(DEBUG, "%s:%d:\n"
 					"tbl: %p, max_entries: %u, use_entries: %u\n"
-					"ipv6_frag_pkt line1: %p, index: %u from %u\n"
+					"ipv4_frag_pkt line1: %p, index: %u from %u\n"
 			"key: <%" PRIx64 ", %#x>, start: %" PRIu64 "\n",
 					__func__, __LINE__,
 					tbl, tbl->max_entries, tbl->use_entries,
diff --git a/v3-0001-net-i40e-add-null-point-check-and-fix-mem-leak.patch b/v3-0001-net-i40e-add-null-point-check-and-fix-mem-leak.patch
new file mode 100644
index 0000000..766ca68
--- /dev/null
+++ b/v3-0001-net-i40e-add-null-point-check-and-fix-mem-leak.patch
@@ -0,0 +1,150 @@
+From b506152e205041f8138e728e135571a024f8a5a6 Mon Sep 17 00:00:00 2001
+From: Yong Wang <wang.yong19 at zte.com.cn>
+Date: Wed, 20 Dec 2017 05:14:28 -0500
+Subject: [PATCH v3 1/3] net/i40e: add null point check and fix mem leak
+
+Signed-off-by: Yong Wang <wang.yong19 at zte.com.cn>
+---
+v2:
+* Fix code style warning.
+---
+ drivers/net/i40e/i40e_ethdev.c | 32 ++++++++++++++++++++++++++++++++
+ drivers/net/i40e/i40e_fdir.c   |  7 +++++++
+ 2 files changed, 39 insertions(+)
+
+diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
+index c4df65d..277c1a8 100644
+--- a/drivers/net/i40e/i40e_ethdev.c
++++ b/drivers/net/i40e/i40e_ethdev.c
+@@ -7188,11 +7188,13 @@ struct i40e_tunnel_filter *
+ 	node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &check_filter.input);
+ 	if (add && node) {
+ 		PMD_DRV_LOG(ERR, "Conflict with existing tunnel rules!");
++		rte_free(cld_filter);
+ 		return -EINVAL;
+ 	}
+ 
+ 	if (!add && !node) {
+ 		PMD_DRV_LOG(ERR, "There's no corresponding tunnel filter!");
++		rte_free(cld_filter);
+ 		return -EINVAL;
+ 	}
+ 
+@@ -7201,16 +7203,26 @@ struct i40e_tunnel_filter *
+ 					vsi->seid, &cld_filter->element, 1);
+ 		if (ret < 0) {
+ 			PMD_DRV_LOG(ERR, "Failed to add a tunnel filter.");
++			rte_free(cld_filter);
+ 			return -ENOTSUP;
+ 		}
+ 		tunnel = rte_zmalloc("tunnel_filter", sizeof(*tunnel), 0);
++		if (tunnel == NULL) {
++			PMD_DRV_LOG(ERR, "Failed to alloc memory.");
++			rte_free(cld_filter);
++			return -ENOMEM;
++		}
++
+ 		rte_memcpy(tunnel, &check_filter, sizeof(check_filter));
+ 		ret = i40e_sw_tunnel_filter_insert(pf, tunnel);
++		if (ret < 0)
++			rte_free(tunnel);
+ 	} else {
+ 		ret = i40e_aq_remove_cloud_filters(hw, vsi->seid,
+ 						   &cld_filter->element, 1);
+ 		if (ret < 0) {
+ 			PMD_DRV_LOG(ERR, "Failed to delete a tunnel filter.");
++			rte_free(cld_filter);
+ 			return -ENOTSUP;
+ 		}
+ 		ret = i40e_sw_tunnel_filter_del(pf, &node->input);
+@@ -7639,6 +7651,7 @@ i40e_status_code i40e_replace_gtp_cloud_filter(struct i40e_pf *pf)
+ 	else {
+ 		if (tunnel_filter->vf_id >= pf->vf_num) {
+ 			PMD_DRV_LOG(ERR, "Invalid argument.");
++			rte_free(cld_filter);
+ 			return -EINVAL;
+ 		}
+ 		vf = &pf->vfs[tunnel_filter->vf_id];
+@@ -7653,11 +7666,13 @@ i40e_status_code i40e_replace_gtp_cloud_filter(struct i40e_pf *pf)
+ 	node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &check_filter.input);
+ 	if (add && node) {
+ 		PMD_DRV_LOG(ERR, "Conflict with existing tunnel rules!");
++		rte_free(cld_filter);
+ 		return -EINVAL;
+ 	}
+ 
+ 	if (!add && !node) {
+ 		PMD_DRV_LOG(ERR, "There's no corresponding tunnel filter!");
++		rte_free(cld_filter);
+ 		return -EINVAL;
+ 	}
+ 
+@@ -7670,11 +7685,20 @@ i40e_status_code i40e_replace_gtp_cloud_filter(struct i40e_pf *pf)
+ 					vsi->seid, &cld_filter->element, 1);
+ 		if (ret < 0) {
+ 			PMD_DRV_LOG(ERR, "Failed to add a tunnel filter.");
++			rte_free(cld_filter);
+ 			return -ENOTSUP;
+ 		}
+ 		tunnel = rte_zmalloc("tunnel_filter", sizeof(*tunnel), 0);
++		if (tunnel == NULL) {
++			PMD_DRV_LOG(ERR, "Failed to alloc memory.");
++			rte_free(cld_filter);
++			return -ENOMEM;
++		}
++
+ 		rte_memcpy(tunnel, &check_filter, sizeof(check_filter));
+ 		ret = i40e_sw_tunnel_filter_insert(pf, tunnel);
++		if (ret < 0)
++			rte_free(tunnel);
+ 	} else {
+ 		if (big_buffer)
+ 			ret = i40e_aq_remove_cloud_filters_big_buffer(
+@@ -7684,6 +7708,7 @@ i40e_status_code i40e_replace_gtp_cloud_filter(struct i40e_pf *pf)
+ 						   &cld_filter->element, 1);
+ 		if (ret < 0) {
+ 			PMD_DRV_LOG(ERR, "Failed to delete a tunnel filter.");
++			rte_free(cld_filter);
+ 			return -ENOTSUP;
+ 		}
+ 		ret = i40e_sw_tunnel_filter_del(pf, &node->input);
+@@ -9295,9 +9320,16 @@ struct i40e_ethertype_filter *
+ 	if (add) {
+ 		ethertype_filter = rte_zmalloc("ethertype_filter",
+ 				       sizeof(*ethertype_filter), 0);
++		if (ethertype_filter == NULL) {
++			PMD_DRV_LOG(ERR, "Failed to alloc memory.");
++			return -ENOMEM;
++		}
++
+ 		rte_memcpy(ethertype_filter, &check_filter,
+ 			   sizeof(check_filter));
+ 		ret = i40e_sw_ethertype_filter_insert(pf, ethertype_filter);
++		if (ret < 0)
++			rte_free(ethertype_filter);
+ 	} else {
+ 		ret = i40e_sw_ethertype_filter_del(pf, &node->input);
+ 	}
+diff --git a/drivers/net/i40e/i40e_fdir.c b/drivers/net/i40e/i40e_fdir.c
+index a4320b1..c392dc4 100644
+--- a/drivers/net/i40e/i40e_fdir.c
++++ b/drivers/net/i40e/i40e_fdir.c
+@@ -1595,8 +1595,15 @@ static int i40e_sw_fdir_filter_insert(struct i40e_pf *pf,
+ 	if (add) {
+ 		fdir_filter = rte_zmalloc("fdir_filter",
+ 					  sizeof(*fdir_filter), 0);
++		if (fdir_filter == NULL) {
++			PMD_DRV_LOG(ERR, "Failed to alloc memory.");
++			return -ENOMEM;
++		}
++
+ 		rte_memcpy(fdir_filter, &check_filter, sizeof(check_filter));
+ 		ret = i40e_sw_fdir_filter_insert(pf, fdir_filter);
++		if (ret < 0)
++			rte_free(fdir_filter);
+ 	} else {
+ 		ret = i40e_sw_fdir_filter_del(pf, &node->fdir.input);
+ 	}
+-- 
+1.8.3.1
+
diff --git a/v3-0002-net-e1000-add-null-point-check-for-rte_zmalloc.patch b/v3-0002-net-e1000-add-null-point-check-for-rte_zmalloc.patch
new file mode 100644
index 0000000..75499b5
--- /dev/null
+++ b/v3-0002-net-e1000-add-null-point-check-for-rte_zmalloc.patch
@@ -0,0 +1,65 @@
+From 52be687c63ba0b44fa9a9ddc172e44525279fe8b Mon Sep 17 00:00:00 2001
+From: Yong Wang <wang.yong19 at zte.com.cn>
+Date: Wed, 20 Dec 2017 05:16:11 -0500
+Subject: [PATCH v3 2/3] net/e1000: add null point check for rte_zmalloc
+
+Signed-off-by: Yong Wang <wang.yong19 at zte.com.cn>
+---
+ drivers/net/e1000/igb_flow.c | 20 ++++++++++++++++++++
+ 1 file changed, 20 insertions(+)
+
+diff --git a/drivers/net/e1000/igb_flow.c b/drivers/net/e1000/igb_flow.c
+index d98bdc8..a142759 100644
+--- a/drivers/net/e1000/igb_flow.c
++++ b/drivers/net/e1000/igb_flow.c
+@@ -1413,6 +1413,11 @@
+ 		if (!ret) {
+ 			ntuple_filter_ptr = rte_zmalloc("igb_ntuple_filter",
+ 				sizeof(struct igb_ntuple_filter_ele), 0);
++			if (!ntuple_filter_ptr) {
++				PMD_DRV_LOG(ERR, "failed to allocate memory");
++				goto out;
++			}
++
+ 			rte_memcpy(&ntuple_filter_ptr->filter_info,
+ 				&ntuple_filter,
+ 				sizeof(struct rte_eth_ntuple_filter));
+@@ -1435,6 +1440,11 @@
+ 			ethertype_filter_ptr = rte_zmalloc(
+ 				"igb_ethertype_filter",
+ 				sizeof(struct igb_ethertype_filter_ele), 0);
++			if (!ethertype_filter_ptr) {
++				PMD_DRV_LOG(ERR, "failed to allocate memory");
++				goto out;
++			}
++
+ 			rte_memcpy(&ethertype_filter_ptr->filter_info,
+ 				&ethertype_filter,
+ 				sizeof(struct rte_eth_ethertype_filter));
+@@ -1455,6 +1465,11 @@
+ 		if (!ret) {
+ 			syn_filter_ptr = rte_zmalloc("igb_syn_filter",
+ 				sizeof(struct igb_eth_syn_filter_ele), 0);
++			if (!syn_filter_ptr) {
++				PMD_DRV_LOG(ERR, "failed to allocate memory");
++				goto out;
++			}
++
+ 			rte_memcpy(&syn_filter_ptr->filter_info,
+ 				&syn_filter,
+ 				sizeof(struct rte_eth_syn_filter));
+@@ -1476,6 +1491,11 @@
+ 		if (!ret) {
+ 			flex_filter_ptr = rte_zmalloc("igb_flex_filter",
+ 				sizeof(struct igb_flex_filter_ele), 0);
++			if (!flex_filter_ptr) {
++				PMD_DRV_LOG(ERR, "failed to allocate memory");
++				goto out;
++			}
++
+ 			rte_memcpy(&flex_filter_ptr->filter_info,
+ 				&flex_filter,
+ 				sizeof(struct rte_eth_flex_filter));
+-- 
+1.8.3.1
+
diff --git a/v3-0003-crypto-qat-add-null-point-check-and-fix-mem-leak.patch b/v3-0003-crypto-qat-add-null-point-check-and-fix-mem-leak.patch
new file mode 100644
index 0000000..f04d485
--- /dev/null
+++ b/v3-0003-crypto-qat-add-null-point-check-and-fix-mem-leak.patch
@@ -0,0 +1,84 @@
+From 492fbb9d1c0afecb7736f360fe278751cfd1b0fc Mon Sep 17 00:00:00 2001
+From: Yong Wang <wang.yong19 at zte.com.cn>
+Date: Wed, 20 Dec 2017 05:18:25 -0500
+Subject: [PATCH v3 3/3] crypto/qat: add null point check and fix mem leak
+
+There are several func calls to rte_zmalloc() which don't do null
+point check on the return value. And before return, the memory is not
+freed. Fix it by adding null point check and rte_free().
+
+Signed-off-by: Yong Wang <wang.yong19 at zte.com.cn>
+---
+v3:
+* Rebase on master and modify again.
+v2:
+* Fix code style warning.
+---
+ drivers/crypto/qat/qat_adf/qat_algs_build_desc.c | 10 ++++++++++
+ drivers/crypto/qat/qat_qp.c                      |  8 +++++++-
+ 2 files changed, 17 insertions(+), 1 deletion(-)
+
+diff --git a/drivers/crypto/qat/qat_adf/qat_algs_build_desc.c b/drivers/crypto/qat/qat_adf/qat_algs_build_desc.c
+index db6c9a3..26f854c 100644
+--- a/drivers/crypto/qat/qat_adf/qat_algs_build_desc.c
++++ b/drivers/crypto/qat/qat_adf/qat_algs_build_desc.c
+@@ -359,6 +359,11 @@ static int qat_alg_do_precomputes(enum icp_qat_hw_auth_algo hash_alg,
+ 
+ 		in = rte_zmalloc("working mem for key",
+ 				ICP_QAT_HW_AES_XCBC_MAC_STATE2_SZ, 16);
++		if (in == NULL) {
++			PMD_DRV_LOG(ERR, "Failed to alloc memory");
++			return -ENOMEM;
++		}
++
+ 		rte_memcpy(in, qat_aes_xcbc_key_seed,
+ 				ICP_QAT_HW_AES_XCBC_MAC_STATE2_SZ);
+ 		for (x = 0; x < HASH_XCBC_PRECOMP_KEY_NUM; x++) {
+@@ -389,6 +394,11 @@ static int qat_alg_do_precomputes(enum icp_qat_hw_auth_algo hash_alg,
+ 				ICP_QAT_HW_GALOIS_E_CTR0_SZ);
+ 		in = rte_zmalloc("working mem for key",
+ 				ICP_QAT_HW_GALOIS_H_SZ, 16);
++		if (in == NULL) {
++			PMD_DRV_LOG(ERR, "Failed to alloc memory");
++			return -ENOMEM;
++		}
++
+ 		memset(in, 0, ICP_QAT_HW_GALOIS_H_SZ);
+ 		if (AES_set_encrypt_key(auth_key, auth_keylen << 3,
+ 			&enc_key) != 0) {
+diff --git a/drivers/crypto/qat/qat_qp.c b/drivers/crypto/qat/qat_qp.c
+index 0941a58..812dce9 100644
+--- a/drivers/crypto/qat/qat_qp.c
++++ b/drivers/crypto/qat/qat_qp.c
+@@ -151,6 +151,11 @@ int qat_crypto_sym_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id,
+ 	qp->op_cookies = rte_zmalloc("qat PMD op cookie pointer",
+ 			qp_conf->nb_descriptors * sizeof(*qp->op_cookies),
+ 			RTE_CACHE_LINE_SIZE);
++	if (qp->op_cookies == NULL) {
++		PMD_DRV_LOG(ERR, "Failed to alloc mem for cookie");
++		rte_free(qp);
++		return -ENOMEM;
++	}
+ 
+ 	qp->mmap_bar_addr = pci_dev->mem_resource[0].addr;
+ 	qp->inflights16 = 0;
+@@ -192,7 +197,7 @@ int qat_crypto_sym_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id,
+ 	for (i = 0; i < qp->nb_descriptors; i++) {
+ 		if (rte_mempool_get(qp->op_cookie_pool, &qp->op_cookies[i])) {
+ 			PMD_DRV_LOG(ERR, "QAT PMD Cannot get op_cookie");
+-			return -EFAULT;
++			goto create_err;
+ 		}
+ 
+ 		struct qat_crypto_op_cookie *sql_cookie =
+@@ -217,6 +222,7 @@ int qat_crypto_sym_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id,
+ 	return 0;
+ 
+ create_err:
++	rte_free(qp->op_cookies);
+ 	rte_free(qp);
+ 	return -EFAULT;
+ }
+-- 
+1.8.3.1
+
diff --git a/v4-0001-crypto-qat-add-null-point-check-and-fix-mem-leak.patch b/v4-0001-crypto-qat-add-null-point-check-and-fix-mem-leak.patch
new file mode 100644
index 0000000..2e2dc2c
--- /dev/null
+++ b/v4-0001-crypto-qat-add-null-point-check-and-fix-mem-leak.patch
@@ -0,0 +1,92 @@
+From 50a235000e02d5e1135ae9ed82809b62027f2fb2 Mon Sep 17 00:00:00 2001
+From: Yong Wang <wang.yong19 at zte.com.cn>
+Date: Wed, 20 Dec 2017 05:18:25 -0500
+Subject: [PATCH v4] crypto/qat: add null point check and fix mem leak
+
+There are several func calls to rte_zmalloc() which don't do null
+point check on the return value. And before return, the memory is not
+freed. Fix it by adding null point check and rte_free().
+
+Fixes: 1703e94ac5ce ("qat: add driver for QuickAssist devices")
+Fixes: e09231eaa2af ("crypto/qat: add SGL capability")
+
+Signed-off-by: Yong Wang <wang.yong19 at zte.com.cn>
+---
+v4:
+* Cover errors that happen after the rte_mempool_create.
+* Add fix information.
+v3:
+* Rebase on master and modify again.
+v2:
+* Fix code style warning.
+---
+ drivers/crypto/qat/qat_adf/qat_algs_build_desc.c | 10 ++++++++++
+ drivers/crypto/qat/qat_qp.c                      | 10 +++++++++-
+ 2 files changed, 19 insertions(+), 1 deletion(-)
+
+diff --git a/drivers/crypto/qat/qat_adf/qat_algs_build_desc.c b/drivers/crypto/qat/qat_adf/qat_algs_build_desc.c
+index db6c9a3..26f854c 100644
+--- a/drivers/crypto/qat/qat_adf/qat_algs_build_desc.c
++++ b/drivers/crypto/qat/qat_adf/qat_algs_build_desc.c
+@@ -359,6 +359,11 @@ static int qat_alg_do_precomputes(enum icp_qat_hw_auth_algo hash_alg,
+ 
+ 		in = rte_zmalloc("working mem for key",
+ 				ICP_QAT_HW_AES_XCBC_MAC_STATE2_SZ, 16);
++		if (in == NULL) {
++			PMD_DRV_LOG(ERR, "Failed to alloc memory");
++			return -ENOMEM;
++		}
++
+ 		rte_memcpy(in, qat_aes_xcbc_key_seed,
+ 				ICP_QAT_HW_AES_XCBC_MAC_STATE2_SZ);
+ 		for (x = 0; x < HASH_XCBC_PRECOMP_KEY_NUM; x++) {
+@@ -389,6 +394,11 @@ static int qat_alg_do_precomputes(enum icp_qat_hw_auth_algo hash_alg,
+ 				ICP_QAT_HW_GALOIS_E_CTR0_SZ);
+ 		in = rte_zmalloc("working mem for key",
+ 				ICP_QAT_HW_GALOIS_H_SZ, 16);
++		if (in == NULL) {
++			PMD_DRV_LOG(ERR, "Failed to alloc memory");
++			return -ENOMEM;
++		}
++
+ 		memset(in, 0, ICP_QAT_HW_GALOIS_H_SZ);
+ 		if (AES_set_encrypt_key(auth_key, auth_keylen << 3,
+ 			&enc_key) != 0) {
+diff --git a/drivers/crypto/qat/qat_qp.c b/drivers/crypto/qat/qat_qp.c
+index 0941a58..87b9ce0 100644
+--- a/drivers/crypto/qat/qat_qp.c
++++ b/drivers/crypto/qat/qat_qp.c
+@@ -151,6 +151,11 @@ int qat_crypto_sym_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id,
+ 	qp->op_cookies = rte_zmalloc("qat PMD op cookie pointer",
+ 			qp_conf->nb_descriptors * sizeof(*qp->op_cookies),
+ 			RTE_CACHE_LINE_SIZE);
++	if (qp->op_cookies == NULL) {
++		PMD_DRV_LOG(ERR, "Failed to alloc mem for cookie");
++		rte_free(qp);
++		return -ENOMEM;
++	}
+ 
+ 	qp->mmap_bar_addr = pci_dev->mem_resource[0].addr;
+ 	qp->inflights16 = 0;
+@@ -192,7 +197,7 @@ int qat_crypto_sym_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id,
+ 	for (i = 0; i < qp->nb_descriptors; i++) {
+ 		if (rte_mempool_get(qp->op_cookie_pool, &qp->op_cookies[i])) {
+ 			PMD_DRV_LOG(ERR, "QAT PMD Cannot get op_cookie");
+-			return -EFAULT;
++			goto create_err;
+ 		}
+ 
+ 		struct qat_crypto_op_cookie *sql_cookie =
+@@ -217,6 +222,9 @@ int qat_crypto_sym_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id,
+ 	return 0;
+ 
+ create_err:
++	if (qp->op_cookie_pool)
++		rte_mempool_free(qp->op_cookie_pool);
++	rte_free(qp->op_cookies);
+ 	rte_free(qp);
+ 	return -EFAULT;
+ }
+-- 
+1.8.3.1
+
diff --git a/v4-0001-net-e1000-add-null-point-check-for-rte_zmalloc.patch b/v4-0001-net-e1000-add-null-point-check-for-rte_zmalloc.patch
new file mode 100644
index 0000000..6f43da0
--- /dev/null
+++ b/v4-0001-net-e1000-add-null-point-check-for-rte_zmalloc.patch
@@ -0,0 +1,77 @@
+From be7c61f3b6b580b9c83bde2b4016fda38be2057a Mon Sep 17 00:00:00 2001
+From: Yong Wang <wang.yong19 at zte.com.cn>
+Date: Wed, 20 Dec 2017 05:16:11 -0500
+Subject: [PATCH v4] net/e1000: add null point check for rte_zmalloc
+
+There are several func calls to rte_zmalloc() which don't do null
+point check on the return value. Fix it by adding null point check.
+
+Fixes: 22bb13410cb2 ("net/igb: create consistent filter")
+
+Signed-off-by: Yong Wang <wang.yong19 at zte.com.cn>
+---
+v4:
+* Add description and fix information.
+v3:
+* Rebase on master and modify again.
+v2:
+* Fix code style warning.
+---
+ drivers/net/e1000/igb_flow.c | 20 ++++++++++++++++++++
+ 1 file changed, 20 insertions(+)
+
+diff --git a/drivers/net/e1000/igb_flow.c b/drivers/net/e1000/igb_flow.c
+index d98bdc8..a142759 100644
+--- a/drivers/net/e1000/igb_flow.c
++++ b/drivers/net/e1000/igb_flow.c
+@@ -1413,6 +1413,11 @@
+ 		if (!ret) {
+ 			ntuple_filter_ptr = rte_zmalloc("igb_ntuple_filter",
+ 				sizeof(struct igb_ntuple_filter_ele), 0);
++			if (!ntuple_filter_ptr) {
++				PMD_DRV_LOG(ERR, "failed to allocate memory");
++				goto out;
++			}
++
+ 			rte_memcpy(&ntuple_filter_ptr->filter_info,
+ 				&ntuple_filter,
+ 				sizeof(struct rte_eth_ntuple_filter));
+@@ -1435,6 +1440,11 @@
+ 			ethertype_filter_ptr = rte_zmalloc(
+ 				"igb_ethertype_filter",
+ 				sizeof(struct igb_ethertype_filter_ele), 0);
++			if (!ethertype_filter_ptr) {
++				PMD_DRV_LOG(ERR, "failed to allocate memory");
++				goto out;
++			}
++
+ 			rte_memcpy(&ethertype_filter_ptr->filter_info,
+ 				&ethertype_filter,
+ 				sizeof(struct rte_eth_ethertype_filter));
+@@ -1455,6 +1465,11 @@
+ 		if (!ret) {
+ 			syn_filter_ptr = rte_zmalloc("igb_syn_filter",
+ 				sizeof(struct igb_eth_syn_filter_ele), 0);
++			if (!syn_filter_ptr) {
++				PMD_DRV_LOG(ERR, "failed to allocate memory");
++				goto out;
++			}
++
+ 			rte_memcpy(&syn_filter_ptr->filter_info,
+ 				&syn_filter,
+ 				sizeof(struct rte_eth_syn_filter));
+@@ -1476,6 +1491,11 @@
+ 		if (!ret) {
+ 			flex_filter_ptr = rte_zmalloc("igb_flex_filter",
+ 				sizeof(struct igb_flex_filter_ele), 0);
++			if (!flex_filter_ptr) {
++				PMD_DRV_LOG(ERR, "failed to allocate memory");
++				goto out;
++			}
++
+ 			rte_memcpy(&flex_filter_ptr->filter_info,
+ 				&flex_filter,
+ 				sizeof(struct rte_eth_flex_filter));
+-- 
+1.8.3.1
+
diff --git a/v4-0001-net-i40e-add-null-point-check-and-fix-mem-leak.patch b/v4-0001-net-i40e-add-null-point-check-and-fix-mem-leak.patch
new file mode 100644
index 0000000..a96d952
--- /dev/null
+++ b/v4-0001-net-i40e-add-null-point-check-and-fix-mem-leak.patch
@@ -0,0 +1,163 @@
+From 8624ca94b94a0f222ca64a93af33d977ea0a004d Mon Sep 17 00:00:00 2001
+From: Yong Wang <wang.yong19 at zte.com.cn>
+Date: Wed, 20 Dec 2017 05:14:28 -0500
+Subject: [PATCH v4] net/i40e: add null point check and fix mem leak
+
+There are several func calls to rte_zmalloc() which don't do null
+point check on the return value. And before return, the memory is not
+freed. Fix it by adding null point check and rte_free().
+
+Fixes: 078259773da9 ("net/i40e: store ethertype filter")
+Fixes: 425c3325f0b0 ("net/i40e: store tunnel filter")
+Fixes: c50474f31efe ("net/i40e: support tunnel filter to VF")
+Fixes: 5c53c82c8174 ("net/i40e: store flow director filter")
+
+Signed-off-by: Yong Wang <wang.yong19 at zte.com.cn>
+---
+v4:
+* Add description and fix information.
+v3:
+* Rebase on master and modify again.
+v2:
+* Fix code style warning.
+---
+ drivers/net/i40e/i40e_ethdev.c | 32 ++++++++++++++++++++++++++++++++
+ drivers/net/i40e/i40e_fdir.c   |  7 +++++++
+ 2 files changed, 39 insertions(+)
+
+diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
+index c4df65d..277c1a8 100644
+--- a/drivers/net/i40e/i40e_ethdev.c
++++ b/drivers/net/i40e/i40e_ethdev.c
+@@ -7188,11 +7188,13 @@ struct i40e_tunnel_filter *
+ 	node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &check_filter.input);
+ 	if (add && node) {
+ 		PMD_DRV_LOG(ERR, "Conflict with existing tunnel rules!");
++		rte_free(cld_filter);
+ 		return -EINVAL;
+ 	}
+ 
+ 	if (!add && !node) {
+ 		PMD_DRV_LOG(ERR, "There's no corresponding tunnel filter!");
++		rte_free(cld_filter);
+ 		return -EINVAL;
+ 	}
+ 
+@@ -7201,16 +7203,26 @@ struct i40e_tunnel_filter *
+ 					vsi->seid, &cld_filter->element, 1);
+ 		if (ret < 0) {
+ 			PMD_DRV_LOG(ERR, "Failed to add a tunnel filter.");
++			rte_free(cld_filter);
+ 			return -ENOTSUP;
+ 		}
+ 		tunnel = rte_zmalloc("tunnel_filter", sizeof(*tunnel), 0);
++		if (tunnel == NULL) {
++			PMD_DRV_LOG(ERR, "Failed to alloc memory.");
++			rte_free(cld_filter);
++			return -ENOMEM;
++		}
++
+ 		rte_memcpy(tunnel, &check_filter, sizeof(check_filter));
+ 		ret = i40e_sw_tunnel_filter_insert(pf, tunnel);
++		if (ret < 0)
++			rte_free(tunnel);
+ 	} else {
+ 		ret = i40e_aq_remove_cloud_filters(hw, vsi->seid,
+ 						   &cld_filter->element, 1);
+ 		if (ret < 0) {
+ 			PMD_DRV_LOG(ERR, "Failed to delete a tunnel filter.");
++			rte_free(cld_filter);
+ 			return -ENOTSUP;
+ 		}
+ 		ret = i40e_sw_tunnel_filter_del(pf, &node->input);
+@@ -7639,6 +7651,7 @@ i40e_status_code i40e_replace_gtp_cloud_filter(struct i40e_pf *pf)
+ 	else {
+ 		if (tunnel_filter->vf_id >= pf->vf_num) {
+ 			PMD_DRV_LOG(ERR, "Invalid argument.");
++			rte_free(cld_filter);
+ 			return -EINVAL;
+ 		}
+ 		vf = &pf->vfs[tunnel_filter->vf_id];
+@@ -7653,11 +7666,13 @@ i40e_status_code i40e_replace_gtp_cloud_filter(struct i40e_pf *pf)
+ 	node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &check_filter.input);
+ 	if (add && node) {
+ 		PMD_DRV_LOG(ERR, "Conflict with existing tunnel rules!");
++		rte_free(cld_filter);
+ 		return -EINVAL;
+ 	}
+ 
+ 	if (!add && !node) {
+ 		PMD_DRV_LOG(ERR, "There's no corresponding tunnel filter!");
++		rte_free(cld_filter);
+ 		return -EINVAL;
+ 	}
+ 
+@@ -7670,11 +7685,20 @@ i40e_status_code i40e_replace_gtp_cloud_filter(struct i40e_pf *pf)
+ 					vsi->seid, &cld_filter->element, 1);
+ 		if (ret < 0) {
+ 			PMD_DRV_LOG(ERR, "Failed to add a tunnel filter.");
++			rte_free(cld_filter);
+ 			return -ENOTSUP;
+ 		}
+ 		tunnel = rte_zmalloc("tunnel_filter", sizeof(*tunnel), 0);
++		if (tunnel == NULL) {
++			PMD_DRV_LOG(ERR, "Failed to alloc memory.");
++			rte_free(cld_filter);
++			return -ENOMEM;
++		}
++
+ 		rte_memcpy(tunnel, &check_filter, sizeof(check_filter));
+ 		ret = i40e_sw_tunnel_filter_insert(pf, tunnel);
++		if (ret < 0)
++			rte_free(tunnel);
+ 	} else {
+ 		if (big_buffer)
+ 			ret = i40e_aq_remove_cloud_filters_big_buffer(
+@@ -7684,6 +7708,7 @@ i40e_status_code i40e_replace_gtp_cloud_filter(struct i40e_pf *pf)
+ 						   &cld_filter->element, 1);
+ 		if (ret < 0) {
+ 			PMD_DRV_LOG(ERR, "Failed to delete a tunnel filter.");
++			rte_free(cld_filter);
+ 			return -ENOTSUP;
+ 		}
+ 		ret = i40e_sw_tunnel_filter_del(pf, &node->input);
+@@ -9295,9 +9320,16 @@ struct i40e_ethertype_filter *
+ 	if (add) {
+ 		ethertype_filter = rte_zmalloc("ethertype_filter",
+ 				       sizeof(*ethertype_filter), 0);
++		if (ethertype_filter == NULL) {
++			PMD_DRV_LOG(ERR, "Failed to alloc memory.");
++			return -ENOMEM;
++		}
++
+ 		rte_memcpy(ethertype_filter, &check_filter,
+ 			   sizeof(check_filter));
+ 		ret = i40e_sw_ethertype_filter_insert(pf, ethertype_filter);
++		if (ret < 0)
++			rte_free(ethertype_filter);
+ 	} else {
+ 		ret = i40e_sw_ethertype_filter_del(pf, &node->input);
+ 	}
+diff --git a/drivers/net/i40e/i40e_fdir.c b/drivers/net/i40e/i40e_fdir.c
+index a4320b1..c392dc4 100644
+--- a/drivers/net/i40e/i40e_fdir.c
++++ b/drivers/net/i40e/i40e_fdir.c
+@@ -1595,8 +1595,15 @@ static int i40e_sw_fdir_filter_insert(struct i40e_pf *pf,
+ 	if (add) {
+ 		fdir_filter = rte_zmalloc("fdir_filter",
+ 					  sizeof(*fdir_filter), 0);
++		if (fdir_filter == NULL) {
++			PMD_DRV_LOG(ERR, "Failed to alloc memory.");
++			return -ENOMEM;
++		}
++
+ 		rte_memcpy(fdir_filter, &check_filter, sizeof(check_filter));
+ 		ret = i40e_sw_fdir_filter_insert(pf, fdir_filter);
++		if (ret < 0)
++			rte_free(fdir_filter);
+ 	} else {
+ 		ret = i40e_sw_fdir_filter_del(pf, &node->fdir.input);
+ 	}
+-- 
+1.8.3.1
+
-- 
1.8.3.1



More information about the dev mailing list