DPDK patches and discussions
 help / color / mirror / Atom feed
From: Weiguo Li <liwg06@foxmail.com>
To: dev@dpdk.org
Cc: adypodoman@gmail.com, xiaoyun.li@intel.com,
	tianfei.zhang@intel.com, bruce.richardson@intel.com,
	ivan.malov@oktetlabs.ru, jgrajcia@cisco.com, hkalra@marvell.com,
	ying.a.wang@intel.com, ting.xu@intel.com, simei.su@intel.com,
	qiming.yang@intel.com, motih@mellanox.com,
	shreyansh.jain@nxp.com, skoteshwar@marvell.com,
	stephen@networkplumber.org, kalesh-anakkur.purayil@broadcom.com,
	somnath.kotur@broadcom.com, declan.doherty@intel.com,
	gakhil@marvell.com, nicolas.chautru@intel.com
Subject: [PATCH 18/20] raw/ifpga/base: fix memory leaks in error handlings
Date: Wed, 23 Feb 2022 02:18:16 +0800	[thread overview]
Message-ID: <tencent_D84ED137D548814867CC048FD7E94504BA06@qq.com> (raw)
In-Reply-To: <cover.1645551559.git.liwg06@foxmail.com>

1) in ifpga_enumerate.c:
The memory 'feature' is stored by TAILQ_INSERT_TAIL() at the end of the
function. When function returned early in error handling, 'feature' is
not released and leads to a memory leak.

2) in opae_eth_group.c and opae_i2c.c
These function return 'dev' when success and return NULL when validation
failed or some error occur. In the latter case 'dev' is not released and
leads to a memory leak.

Fixes: 56bb54ea1bdf ("raw/ifpga/base: add Intel FPGA OPAE share code")
Fixes: 12f92a513a13 ("raw/ifpga/base: fix retimer link status")
Fixes: 15d21c851028 ("raw/ifpga/base: add I2C and at24 EEPROM driver")

Signed-off-by: Weiguo Li <liwg06@foxmail.com>
---
 drivers/raw/ifpga/base/ifpga_enumerate.c | 10 ++++++++--
 drivers/raw/ifpga/base/opae_eth_group.c  |  1 +
 drivers/raw/ifpga/base/opae_i2c.c        |  5 ++++-
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/raw/ifpga/base/ifpga_enumerate.c b/drivers/raw/ifpga/base/ifpga_enumerate.c
index 48b8af4587..ae7bc9326d 100644
--- a/drivers/raw/ifpga/base/ifpga_enumerate.c
+++ b/drivers/raw/ifpga/base/ifpga_enumerate.c
@@ -100,12 +100,16 @@ build_info_add_sub_feature(struct build_feature_devs_info *binfo,
 			(unsigned long long)feature->phys_addr, size);
 
 	if (vec_cnt) {
-		if (vec_start + vec_cnt <= vec_start)
+		if (vec_start + vec_cnt <= vec_start) {
+			opae_free(feature);
 			return -EINVAL;
+		}
 
 		ctx = zmalloc(sizeof(*ctx) * vec_cnt);
-		if (!ctx)
+		if (!ctx) {
+			opae_free(feature);
 			return -ENOMEM;
+		}
 
 		for (i = 0; i < vec_cnt; i++) {
 			ctx[i].eventfd = -1;
@@ -130,6 +134,8 @@ build_info_add_sub_feature(struct build_feature_devs_info *binfo,
 		TAILQ_INSERT_TAIL(&hw->port[port_id].feature_list,
 				feature, next);
 	} else {
+		opae_free(feature->ctx);
+		opae_free(feature);
 		return -EFAULT;
 	}
 	return ret;
diff --git a/drivers/raw/ifpga/base/opae_eth_group.c b/drivers/raw/ifpga/base/opae_eth_group.c
index be28954e05..cd9b2443c7 100644
--- a/drivers/raw/ifpga/base/opae_eth_group.c
+++ b/drivers/raw/ifpga/base/opae_eth_group.c
@@ -297,6 +297,7 @@ struct eth_group_device *eth_group_probe(void *base)
 
 	if (eth_group_hw_init(dev)) {
 		dev_err(dev, "eth group hw init fail\n");
+		opae_free(dev);
 		return NULL;
 	}
 
diff --git a/drivers/raw/ifpga/base/opae_i2c.c b/drivers/raw/ifpga/base/opae_i2c.c
index 598eab5742..0a9abff14d 100644
--- a/drivers/raw/ifpga/base/opae_i2c.c
+++ b/drivers/raw/ifpga/base/opae_i2c.c
@@ -479,6 +479,7 @@ struct altera_i2c_dev *altera_i2c_probe(void *base)
 
 	if (dev->i2c_param.devid != 0xEE011) {
 		dev_err(dev, "find a invalid i2c master\n");
+		opae_free(dev);
 		return NULL;
 	}
 
@@ -494,8 +495,10 @@ struct altera_i2c_dev *altera_i2c_probe(void *base)
 	dev->i2c_clk = dev->i2c_param.ref_clk * 1000000;
 	dev->xfer = altera_i2c_xfer;
 
-	if (pthread_mutex_init(&dev->lock, NULL))
+	if (pthread_mutex_init(&dev->lock, NULL)) {
+		opae_free(dev);
 		return NULL;
+	}
 	dev->mutex = &dev->lock;
 
 	altera_i2c_hardware_init(dev);
-- 
2.25.1


  parent reply	other threads:[~2022-02-22 18:20 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1645551559.git.liwg06@foxmail.com>
2022-02-22 18:17 ` [PATCH 01/20] baseband/acc100: fix a memory leak in acc100 queue setup Weiguo Li
2022-02-23 17:42   ` Chautru, Nicolas
2022-06-24 20:45   ` David Marchand
2022-02-22 18:18 ` [PATCH 02/20] common/dpaax: fix a memory leak in iterate dir Weiguo Li
2022-02-22 18:18 ` [PATCH 03/20] crypto/dpaa2_sec: fix memory leaks in error handlings Weiguo Li
2022-06-24 20:46   ` David Marchand
2022-02-22 18:18 ` [PATCH 04/20] crypto/qat: fix a memory leak when set encrypt key fail Weiguo Li
2022-06-24 20:49   ` David Marchand
2022-02-22 18:18 ` [PATCH 05/20] net/bnxt: fix a memory leak in error handling Weiguo Li
2022-02-22 18:18 ` [PATCH 06/20] net/bnxt: fix 'ctx' memory leak when new malloc fail Weiguo Li
2022-02-22 18:18 ` [PATCH 07/20] net/bnx2x: add clean up for 'rxq' to avoid a memory leak Weiguo Li
2022-02-22 18:18 ` [PATCH 08/20] net/cnxk: free 'node' memory when node add fail Weiguo Li
2022-04-07  9:02   ` Nithin Kumar Dabilpuram
2022-02-22 18:18 ` [PATCH 09/20] net/dpaa: fix a memory leak when validation fail Weiguo Li
2022-02-22 18:18 ` [PATCH 10/20] net/failsafe: fix a memory leak in error handling Weiguo Li
2022-02-22 18:18 ` [PATCH 11/20] net/iavf: " Weiguo Li
2022-02-22 18:18 ` [PATCH 12/20] net/ice: goto clean up lable to avoid memory leak Weiguo Li
2022-02-22 18:18 ` [PATCH 13/20] net/ice: fix memory leaks in error handlings Weiguo Li
2022-06-02  8:04   ` David Marchand
2022-02-22 18:18 ` [PATCH 14/20] net/ice: avoid fix memory leaks in register parser Weiguo Li
2022-02-22 18:18 ` [PATCH 15/20] net/memif: fix some memory leaks in error handlings Weiguo Li
2022-02-22 18:18 ` [PATCH 16/20] net/sfc: fix a memory leak in error handling Weiguo Li
2022-03-03  7:39   ` Andrew Rybchenko
2022-02-22 18:18 ` [PATCH 17/20] net/vmxnet3: fix memory leaks in error handlings Weiguo Li
2022-02-22 18:18 ` Weiguo Li [this message]
2022-02-22 18:28 ` [PATCH 19/20] raw/ntb: fix some " Weiguo Li
2022-02-22 18:28 ` [PATCH 20/20] regex/mlx5: fix a memory leak in error handling Weiguo Li

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=tencent_D84ED137D548814867CC048FD7E94504BA06@qq.com \
    --to=liwg06@foxmail.com \
    --cc=adypodoman@gmail.com \
    --cc=bruce.richardson@intel.com \
    --cc=declan.doherty@intel.com \
    --cc=dev@dpdk.org \
    --cc=gakhil@marvell.com \
    --cc=hkalra@marvell.com \
    --cc=ivan.malov@oktetlabs.ru \
    --cc=jgrajcia@cisco.com \
    --cc=kalesh-anakkur.purayil@broadcom.com \
    --cc=motih@mellanox.com \
    --cc=nicolas.chautru@intel.com \
    --cc=qiming.yang@intel.com \
    --cc=shreyansh.jain@nxp.com \
    --cc=simei.su@intel.com \
    --cc=skoteshwar@marvell.com \
    --cc=somnath.kotur@broadcom.com \
    --cc=stephen@networkplumber.org \
    --cc=tianfei.zhang@intel.com \
    --cc=ting.xu@intel.com \
    --cc=xiaoyun.li@intel.com \
    --cc=ying.a.wang@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).