DPDK patches and discussions
 help / color / Atom feed
* [dpdk-dev] [PATCH] baseband/turbo_sw: fix memory leak in error path
@ 2020-10-07  9:03 wangyunjian
  2020-10-07 23:45 ` Chautru, Nicolas
  2020-10-15 13:45 ` [dpdk-dev] [PATCH v2] " wangyunjian
  0 siblings, 2 replies; 6+ messages in thread
From: wangyunjian @ 2020-10-07  9:03 UTC (permalink / raw)
  To: dev; +Cc: nicolas.chautru, jerry.lilijun, xudingke, Yunjian Wang, stable

From: Yunjian Wang <wangyunjian@huawei.com>

In q_setup() allocated memory for the queue data, we should free
it when error happens, otherwise it will lead to memory leak.

Fixes: b8cfe2c9aed2 ("bb/turbo_sw: add software turbo driver")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
 drivers/baseband/turbo_sw/bbdev_turbo_software.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/baseband/turbo_sw/bbdev_turbo_software.c b/drivers/baseband/turbo_sw/bbdev_turbo_software.c
index a36099e91..e55b32927 100644
--- a/drivers/baseband/turbo_sw/bbdev_turbo_software.c
+++ b/drivers/baseband/turbo_sw/bbdev_turbo_software.c
@@ -302,7 +302,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
 		rte_bbdev_log(ERR,
 				"Creating queue name for device %u queue %u failed",
 				dev->data->dev_id, q_id);
-		return -ENAMETOOLONG;
+		goto free_q;
 	}
 	q->enc_out = rte_zmalloc_socket(name,
 			((RTE_BBDEV_TURBO_MAX_TB_SIZE >> 3) + 3) *
@@ -322,7 +322,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
 		rte_bbdev_log(ERR,
 				"Creating queue name for device %u queue %u failed",
 				dev->data->dev_id, q_id);
-		return -ENAMETOOLONG;
+		goto free_q;
 	}
 	q->enc_in = rte_zmalloc_socket(name,
 			(RTE_BBDEV_LDPC_MAX_CB_SIZE >> 3) * sizeof(*q->enc_in),
@@ -340,7 +340,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
 		rte_bbdev_log(ERR,
 				"Creating queue name for device %u queue %u failed",
 				dev->data->dev_id, q_id);
-		return -ENAMETOOLONG;
+		goto free_q;
 	}
 	q->ag = rte_zmalloc_socket(name,
 			RTE_BBDEV_TURBO_MAX_CB_SIZE * 10 * sizeof(*q->ag),
@@ -358,7 +358,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
 		rte_bbdev_log(ERR,
 				"Creating queue name for device %u queue %u failed",
 				dev->data->dev_id, q_id);
-		return -ENAMETOOLONG;
+		goto free_q;
 	}
 	q->code_block = rte_zmalloc_socket(name,
 			RTE_BBDEV_TURBO_MAX_CB_SIZE * sizeof(*q->code_block),
@@ -377,7 +377,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
 		rte_bbdev_log(ERR,
 				"Creating queue name for device %u queue %u failed",
 				dev->data->dev_id, q_id);
-		return -ENAMETOOLONG;
+		goto free_q;
 	}
 	q->deint_input = rte_zmalloc_socket(name,
 			DEINT_INPUT_BUF_SIZE * sizeof(*q->deint_input),
@@ -396,7 +396,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
 		rte_bbdev_log(ERR,
 				"Creating queue name for device %u queue %u failed",
 				dev->data->dev_id, q_id);
-		return -ENAMETOOLONG;
+		goto free_q;
 	}
 	q->deint_output = rte_zmalloc_socket(NULL,
 			DEINT_OUTPUT_BUF_SIZE * sizeof(*q->deint_output),
@@ -415,7 +415,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
 		rte_bbdev_log(ERR,
 				"Creating queue name for device %u queue %u failed",
 				dev->data->dev_id, q_id);
-		return -ENAMETOOLONG;
+		goto free_q;
 	}
 	q->adapter_output = rte_zmalloc_socket(NULL,
 			ADAPTER_OUTPUT_BUF_SIZE * sizeof(*q->adapter_output),
@@ -433,7 +433,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
 		rte_bbdev_log(ERR,
 				"Creating queue name for device %u queue %u failed",
 				dev->data->dev_id, q_id);
-		return -ENAMETOOLONG;
+		goto free_q;
 	}
 	q->processed_pkts = rte_ring_create(name, queue_conf->queue_size,
 			queue_conf->socket, RING_F_SP_ENQ | RING_F_SC_DEQ);
-- 
2.23.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [dpdk-dev] [PATCH] baseband/turbo_sw: fix memory leak in error path
  2020-10-07  9:03 [dpdk-dev] [PATCH] baseband/turbo_sw: fix memory leak in error path wangyunjian
@ 2020-10-07 23:45 ` Chautru, Nicolas
  2020-10-15 12:50   ` wangyunjian
  2020-10-15 13:45 ` [dpdk-dev] [PATCH v2] " wangyunjian
  1 sibling, 1 reply; 6+ messages in thread
From: Chautru, Nicolas @ 2020-10-07 23:45 UTC (permalink / raw)
  To: wangyunjian, dev; +Cc: jerry.lilijun, xudingke, stable

Hi wangyunjian,

> -----Original Message-----
> From: wangyunjian <wangyunjian@huawei.com>
> Sent: Wednesday, October 7, 2020 2:04 AM
> To: dev@dpdk.org
> Cc: Chautru, Nicolas <nicolas.chautru@intel.com>; jerry.lilijun@huawei.com;
> xudingke@huawei.com; Yunjian Wang <wangyunjian@huawei.com>;
> stable@dpdk.org
> Subject: [dpdk-dev] [PATCH] baseband/turbo_sw: fix memory leak in error
> path
> 
> From: Yunjian Wang <wangyunjian@huawei.com>
> 
> In q_setup() allocated memory for the queue data, we should free it when
> error happens, otherwise it will lead to memory leak.
> 
> Fixes: b8cfe2c9aed2 ("bb/turbo_sw: add software turbo driver")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---
>  drivers/baseband/turbo_sw/bbdev_turbo_software.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/baseband/turbo_sw/bbdev_turbo_software.c
> b/drivers/baseband/turbo_sw/bbdev_turbo_software.c
> index a36099e91..e55b32927 100644
> --- a/drivers/baseband/turbo_sw/bbdev_turbo_software.c
> +++ b/drivers/baseband/turbo_sw/bbdev_turbo_software.c
> @@ -302,7 +302,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
>  		rte_bbdev_log(ERR,
>  				"Creating queue name for device %u queue
> %u failed",
>  				dev->data->dev_id, q_id);
> -		return -ENAMETOOLONG;
> +		goto free_q;

It may be better to move the freeing into a common function and return the relevant failure ENUM for each failure reason. 
With the proposed changed it would always return EFAULT to application.

For information did you ever catch that exception from actually running the code or purely from code review? I struggle to see that error genuinely happening.

Thanks,
Nic

>  	}
>  	q->enc_out = rte_zmalloc_socket(name,
>  			((RTE_BBDEV_TURBO_MAX_TB_SIZE >> 3) + 3) * @@
> -322,7 +322,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
>  		rte_bbdev_log(ERR,
>  				"Creating queue name for device %u queue
> %u failed",
>  				dev->data->dev_id, q_id);
> -		return -ENAMETOOLONG;
> +		goto free_q;
>  	}
>  	q->enc_in = rte_zmalloc_socket(name,
>  			(RTE_BBDEV_LDPC_MAX_CB_SIZE >> 3) * sizeof(*q-
> >enc_in), @@ -340,7 +340,7 @@ q_setup(struct rte_bbdev *dev, uint16_t
> q_id,
>  		rte_bbdev_log(ERR,
>  				"Creating queue name for device %u queue
> %u failed",
>  				dev->data->dev_id, q_id);
> -		return -ENAMETOOLONG;
> +		goto free_q;
>  	}
>  	q->ag = rte_zmalloc_socket(name,
>  			RTE_BBDEV_TURBO_MAX_CB_SIZE * 10 * sizeof(*q-
> >ag), @@ -358,7 +358,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
>  		rte_bbdev_log(ERR,
>  				"Creating queue name for device %u queue
> %u failed",
>  				dev->data->dev_id, q_id);
> -		return -ENAMETOOLONG;
> +		goto free_q;
>  	}
>  	q->code_block = rte_zmalloc_socket(name,
>  			RTE_BBDEV_TURBO_MAX_CB_SIZE * sizeof(*q-
> >code_block), @@ -377,7 +377,7 @@ q_setup(struct rte_bbdev *dev,
> uint16_t q_id,
>  		rte_bbdev_log(ERR,
>  				"Creating queue name for device %u queue
> %u failed",
>  				dev->data->dev_id, q_id);
> -		return -ENAMETOOLONG;
> +		goto free_q;
>  	}
>  	q->deint_input = rte_zmalloc_socket(name,
>  			DEINT_INPUT_BUF_SIZE * sizeof(*q->deint_input),
> @@ -396,7 +396,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
>  		rte_bbdev_log(ERR,
>  				"Creating queue name for device %u queue
> %u failed",
>  				dev->data->dev_id, q_id);
> -		return -ENAMETOOLONG;
> +		goto free_q;
>  	}
>  	q->deint_output = rte_zmalloc_socket(NULL,
>  			DEINT_OUTPUT_BUF_SIZE * sizeof(*q-
> >deint_output), @@ -415,7 +415,7 @@ q_setup(struct rte_bbdev *dev,
> uint16_t q_id,
>  		rte_bbdev_log(ERR,
>  				"Creating queue name for device %u queue
> %u failed",
>  				dev->data->dev_id, q_id);
> -		return -ENAMETOOLONG;
> +		goto free_q;
>  	}
>  	q->adapter_output = rte_zmalloc_socket(NULL,
>  			ADAPTER_OUTPUT_BUF_SIZE * sizeof(*q-
> >adapter_output), @@ -433,7 +433,7 @@ q_setup(struct rte_bbdev *dev,
> uint16_t q_id,
>  		rte_bbdev_log(ERR,
>  				"Creating queue name for device %u queue
> %u failed",
>  				dev->data->dev_id, q_id);
> -		return -ENAMETOOLONG;
> +		goto free_q;
>  	}
>  	q->processed_pkts = rte_ring_create(name, queue_conf-
> >queue_size,
>  			queue_conf->socket, RING_F_SP_ENQ |
> RING_F_SC_DEQ);
> --
> 2.23.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [dpdk-dev] [PATCH] baseband/turbo_sw: fix memory leak in error path
  2020-10-07 23:45 ` Chautru, Nicolas
@ 2020-10-15 12:50   ` wangyunjian
  0 siblings, 0 replies; 6+ messages in thread
From: wangyunjian @ 2020-10-15 12:50 UTC (permalink / raw)
  To: Chautru, Nicolas, dev; +Cc: Lilijun (Jerry), xudingke, stable

> -----Original Message-----
> From: Chautru, Nicolas [mailto:nicolas.chautru@intel.com]
> Sent: Thursday, October 8, 2020 7:45 AM
> To: wangyunjian <wangyunjian@huawei.com>; dev@dpdk.org
> Cc: Lilijun (Jerry) <jerry.lilijun@huawei.com>; xudingke
> <xudingke@huawei.com>; stable@dpdk.org
> Subject: RE: [dpdk-dev] [PATCH] baseband/turbo_sw: fix memory leak in error
> path
> 
> Hi wangyunjian,
> 
> > -----Original Message-----
> > From: wangyunjian <wangyunjian@huawei.com>
> > Sent: Wednesday, October 7, 2020 2:04 AM
> > To: dev@dpdk.org
> > Cc: Chautru, Nicolas <nicolas.chautru@intel.com>;
> > jerry.lilijun@huawei.com; xudingke@huawei.com; Yunjian Wang
> > <wangyunjian@huawei.com>; stable@dpdk.org
> > Subject: [dpdk-dev] [PATCH] baseband/turbo_sw: fix memory leak in
> > error path
> >
> > From: Yunjian Wang <wangyunjian@huawei.com>
> >
> > In q_setup() allocated memory for the queue data, we should free it
> > when error happens, otherwise it will lead to memory leak.
> >
> > Fixes: b8cfe2c9aed2 ("bb/turbo_sw: add software turbo driver")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> > ---
> >  drivers/baseband/turbo_sw/bbdev_turbo_software.c | 16
> > ++++++++--------
> >  1 file changed, 8 insertions(+), 8 deletions(-)
> >
> > diff --git a/drivers/baseband/turbo_sw/bbdev_turbo_software.c
> > b/drivers/baseband/turbo_sw/bbdev_turbo_software.c
> > index a36099e91..e55b32927 100644
> > --- a/drivers/baseband/turbo_sw/bbdev_turbo_software.c
> > +++ b/drivers/baseband/turbo_sw/bbdev_turbo_software.c
> > @@ -302,7 +302,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
> >  		rte_bbdev_log(ERR,
> >  				"Creating queue name for device %u queue %u failed",
> >  				dev->data->dev_id, q_id);
> > -		return -ENAMETOOLONG;
> > +		goto free_q;
> 
> It may be better to move the freeing into a common function and return the
> relevant failure ENUM for each failure reason.
> With the proposed changed it would always return EFAULT to application.
> 
> For information did you ever catch that exception from actually running the
> code or purely from code review? I struggle to see that error genuinely
> happening.

By code review. I will fix return code in the next version.

Thanks,
Yunjian

> 
> Thanks,
> Nic
> 
> >  	}
> >  	q->enc_out = rte_zmalloc_socket(name,
> >  			((RTE_BBDEV_TURBO_MAX_TB_SIZE >> 3) + 3) * @@
> > -322,7 +322,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
> >  		rte_bbdev_log(ERR,
> >  				"Creating queue name for device %u queue %u failed",
> >  				dev->data->dev_id, q_id);
> > -		return -ENAMETOOLONG;
> > +		goto free_q;
> >  	}
> >  	q->enc_in = rte_zmalloc_socket(name,
> >  			(RTE_BBDEV_LDPC_MAX_CB_SIZE >> 3) * sizeof(*q-
> > >enc_in), @@ -340,7 +340,7 @@ q_setup(struct rte_bbdev *dev, uint16_t
> > q_id,
> >  		rte_bbdev_log(ERR,
> >  				"Creating queue name for device %u queue %u failed",
> >  				dev->data->dev_id, q_id);
> > -		return -ENAMETOOLONG;
> > +		goto free_q;
> >  	}
> >  	q->ag = rte_zmalloc_socket(name,
> >  			RTE_BBDEV_TURBO_MAX_CB_SIZE * 10 * sizeof(*q-
> > >ag), @@ -358,7 +358,7 @@ q_setup(struct rte_bbdev *dev, uint16_t
> > >q_id,
> >  		rte_bbdev_log(ERR,
> >  				"Creating queue name for device %u queue %u failed",
> >  				dev->data->dev_id, q_id);
> > -		return -ENAMETOOLONG;
> > +		goto free_q;
> >  	}
> >  	q->code_block = rte_zmalloc_socket(name,
> >  			RTE_BBDEV_TURBO_MAX_CB_SIZE * sizeof(*q-
> > >code_block), @@ -377,7 +377,7 @@ q_setup(struct rte_bbdev *dev,
> > uint16_t q_id,
> >  		rte_bbdev_log(ERR,
> >  				"Creating queue name for device %u queue %u failed",
> >  				dev->data->dev_id, q_id);
> > -		return -ENAMETOOLONG;
> > +		goto free_q;
> >  	}
> >  	q->deint_input = rte_zmalloc_socket(name,
> >  			DEINT_INPUT_BUF_SIZE * sizeof(*q->deint_input), @@ -396,7
> +396,7
> > @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
> >  		rte_bbdev_log(ERR,
> >  				"Creating queue name for device %u queue %u failed",
> >  				dev->data->dev_id, q_id);
> > -		return -ENAMETOOLONG;
> > +		goto free_q;
> >  	}
> >  	q->deint_output = rte_zmalloc_socket(NULL,
> >  			DEINT_OUTPUT_BUF_SIZE * sizeof(*q-
> > >deint_output), @@ -415,7 +415,7 @@ q_setup(struct rte_bbdev *dev,
> > uint16_t q_id,
> >  		rte_bbdev_log(ERR,
> >  				"Creating queue name for device %u queue %u failed",
> >  				dev->data->dev_id, q_id);
> > -		return -ENAMETOOLONG;
> > +		goto free_q;
> >  	}
> >  	q->adapter_output = rte_zmalloc_socket(NULL,
> >  			ADAPTER_OUTPUT_BUF_SIZE * sizeof(*q-
> > >adapter_output), @@ -433,7 +433,7 @@ q_setup(struct rte_bbdev *dev,
> > uint16_t q_id,
> >  		rte_bbdev_log(ERR,
> >  				"Creating queue name for device %u queue %u failed",
> >  				dev->data->dev_id, q_id);
> > -		return -ENAMETOOLONG;
> > +		goto free_q;
> >  	}
> >  	q->processed_pkts = rte_ring_create(name, queue_conf-
> > >queue_size,
> >  			queue_conf->socket, RING_F_SP_ENQ | RING_F_SC_DEQ);
> > --
> > 2.23.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [dpdk-dev] [PATCH v2] baseband/turbo_sw: fix memory leak in error path
  2020-10-07  9:03 [dpdk-dev] [PATCH] baseband/turbo_sw: fix memory leak in error path wangyunjian
  2020-10-07 23:45 ` Chautru, Nicolas
@ 2020-10-15 13:45 ` " wangyunjian
  2020-10-17  0:22   ` Chautru, Nicolas
  2020-10-28 11:29   ` Akhil Goyal
  1 sibling, 2 replies; 6+ messages in thread
From: wangyunjian @ 2020-10-15 13:45 UTC (permalink / raw)
  To: dev; +Cc: nicolas.chautru, jerry.lilijun, xudingke, Yunjian Wang, stable

From: Yunjian Wang <wangyunjian@huawei.com>

In q_setup() allocated memory for the queue data, we should free
it when error happens, otherwise it will lead to memory leak.

Fixes: b8cfe2c9aed2 ("bb/turbo_sw: add software turbo driver")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
v2:
   fix code styles Chautru Nicolas
---
 .../baseband/turbo_sw/bbdev_turbo_software.c  | 35 ++++++++++++++-----
 1 file changed, 26 insertions(+), 9 deletions(-)

diff --git a/drivers/baseband/turbo_sw/bbdev_turbo_software.c b/drivers/baseband/turbo_sw/bbdev_turbo_software.c
index a36099e91..aa7f12238 100644
--- a/drivers/baseband/turbo_sw/bbdev_turbo_software.c
+++ b/drivers/baseband/turbo_sw/bbdev_turbo_software.c
@@ -10,6 +10,7 @@
 #include <rte_ring.h>
 #include <rte_kvargs.h>
 #include <rte_cycles.h>
+#include <rte_errno.h>
 
 #include <rte_bbdev.h>
 #include <rte_bbdev_pmd.h>
@@ -302,7 +303,8 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
 		rte_bbdev_log(ERR,
 				"Creating queue name for device %u queue %u failed",
 				dev->data->dev_id, q_id);
-		return -ENAMETOOLONG;
+		ret = -ENAMETOOLONG;
+		goto free_q;
 	}
 	q->enc_out = rte_zmalloc_socket(name,
 			((RTE_BBDEV_TURBO_MAX_TB_SIZE >> 3) + 3) *
@@ -311,6 +313,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
 	if (q->enc_out == NULL) {
 		rte_bbdev_log(ERR,
 			"Failed to allocate queue memory for %s", name);
+		ret = -ENOMEM;
 		goto free_q;
 	}
 
@@ -322,7 +325,8 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
 		rte_bbdev_log(ERR,
 				"Creating queue name for device %u queue %u failed",
 				dev->data->dev_id, q_id);
-		return -ENAMETOOLONG;
+		ret = -ENAMETOOLONG;
+		goto free_q;
 	}
 	q->enc_in = rte_zmalloc_socket(name,
 			(RTE_BBDEV_LDPC_MAX_CB_SIZE >> 3) * sizeof(*q->enc_in),
@@ -330,6 +334,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
 	if (q->enc_in == NULL) {
 		rte_bbdev_log(ERR,
 			"Failed to allocate queue memory for %s", name);
+		ret = -ENOMEM;
 		goto free_q;
 	}
 
@@ -340,7 +345,8 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
 		rte_bbdev_log(ERR,
 				"Creating queue name for device %u queue %u failed",
 				dev->data->dev_id, q_id);
-		return -ENAMETOOLONG;
+		ret = -ENAMETOOLONG;
+		goto free_q;
 	}
 	q->ag = rte_zmalloc_socket(name,
 			RTE_BBDEV_TURBO_MAX_CB_SIZE * 10 * sizeof(*q->ag),
@@ -348,6 +354,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
 	if (q->ag == NULL) {
 		rte_bbdev_log(ERR,
 			"Failed to allocate queue memory for %s", name);
+		ret = -ENOMEM;
 		goto free_q;
 	}
 
@@ -358,7 +365,8 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
 		rte_bbdev_log(ERR,
 				"Creating queue name for device %u queue %u failed",
 				dev->data->dev_id, q_id);
-		return -ENAMETOOLONG;
+		ret = -ENAMETOOLONG;
+		goto free_q;
 	}
 	q->code_block = rte_zmalloc_socket(name,
 			RTE_BBDEV_TURBO_MAX_CB_SIZE * sizeof(*q->code_block),
@@ -366,6 +374,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
 	if (q->code_block == NULL) {
 		rte_bbdev_log(ERR,
 			"Failed to allocate queue memory for %s", name);
+		ret = -ENOMEM;
 		goto free_q;
 	}
 
@@ -377,7 +386,8 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
 		rte_bbdev_log(ERR,
 				"Creating queue name for device %u queue %u failed",
 				dev->data->dev_id, q_id);
-		return -ENAMETOOLONG;
+		ret = -ENAMETOOLONG;
+		goto free_q;
 	}
 	q->deint_input = rte_zmalloc_socket(name,
 			DEINT_INPUT_BUF_SIZE * sizeof(*q->deint_input),
@@ -385,6 +395,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
 	if (q->deint_input == NULL) {
 		rte_bbdev_log(ERR,
 			"Failed to allocate queue memory for %s", name);
+		ret = -ENOMEM;
 		goto free_q;
 	}
 
@@ -396,7 +407,8 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
 		rte_bbdev_log(ERR,
 				"Creating queue name for device %u queue %u failed",
 				dev->data->dev_id, q_id);
-		return -ENAMETOOLONG;
+		ret = -ENAMETOOLONG;
+		goto free_q;
 	}
 	q->deint_output = rte_zmalloc_socket(NULL,
 			DEINT_OUTPUT_BUF_SIZE * sizeof(*q->deint_output),
@@ -404,6 +416,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
 	if (q->deint_output == NULL) {
 		rte_bbdev_log(ERR,
 			"Failed to allocate queue memory for %s", name);
+		ret = -ENOMEM;
 		goto free_q;
 	}
 
@@ -415,7 +428,8 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
 		rte_bbdev_log(ERR,
 				"Creating queue name for device %u queue %u failed",
 				dev->data->dev_id, q_id);
-		return -ENAMETOOLONG;
+		ret = -ENAMETOOLONG;
+		goto free_q;
 	}
 	q->adapter_output = rte_zmalloc_socket(NULL,
 			ADAPTER_OUTPUT_BUF_SIZE * sizeof(*q->adapter_output),
@@ -423,6 +437,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
 	if (q->adapter_output == NULL) {
 		rte_bbdev_log(ERR,
 			"Failed to allocate queue memory for %s", name);
+		ret = -ENOMEM;
 		goto free_q;
 	}
 
@@ -433,12 +448,14 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
 		rte_bbdev_log(ERR,
 				"Creating queue name for device %u queue %u failed",
 				dev->data->dev_id, q_id);
-		return -ENAMETOOLONG;
+		ret = -ENAMETOOLONG;
+		goto free_q;
 	}
 	q->processed_pkts = rte_ring_create(name, queue_conf->queue_size,
 			queue_conf->socket, RING_F_SP_ENQ | RING_F_SC_DEQ);
 	if (q->processed_pkts == NULL) {
 		rte_bbdev_log(ERR, "Failed to create ring for %s", name);
+		ret = -rte_errno;
 		goto free_q;
 	}
 
@@ -458,7 +475,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
 	rte_free(q->deint_output);
 	rte_free(q->adapter_output);
 	rte_free(q);
-	return -EFAULT;
+	return ret;
 }
 
 static const struct rte_bbdev_ops pmd_ops = {
-- 
2.23.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [dpdk-dev] [PATCH v2] baseband/turbo_sw: fix memory leak in error path
  2020-10-15 13:45 ` [dpdk-dev] [PATCH v2] " wangyunjian
@ 2020-10-17  0:22   ` Chautru, Nicolas
  2020-10-28 11:29   ` Akhil Goyal
  1 sibling, 0 replies; 6+ messages in thread
From: Chautru, Nicolas @ 2020-10-17  0:22 UTC (permalink / raw)
  To: wangyunjian, dev; +Cc: jerry.lilijun, xudingke, stable

Thanks
Reviewed-by: Nicolas Chautru <nicolas.chautru@intel.com>

> -----Original Message-----
> From: wangyunjian <wangyunjian@huawei.com>
> Sent: Thursday, October 15, 2020 6:46 AM
> To: dev@dpdk.org
> Cc: Chautru, Nicolas <nicolas.chautru@intel.com>; jerry.lilijun@huawei.com;
> xudingke@huawei.com; Yunjian Wang <wangyunjian@huawei.com>;
> stable@dpdk.org
> Subject: [dpdk-dev] [PATCH v2] baseband/turbo_sw: fix memory leak in error
> path
> 
> From: Yunjian Wang <wangyunjian@huawei.com>
> 
> In q_setup() allocated memory for the queue data, we should free it when
> error happens, otherwise it will lead to memory leak.
> 
> Fixes: b8cfe2c9aed2 ("bb/turbo_sw: add software turbo driver")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---
> v2:
>    fix code styles Chautru Nicolas
> ---
>  .../baseband/turbo_sw/bbdev_turbo_software.c  | 35 ++++++++++++++-----
>  1 file changed, 26 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/baseband/turbo_sw/bbdev_turbo_software.c
> b/drivers/baseband/turbo_sw/bbdev_turbo_software.c
> index a36099e91..aa7f12238 100644
> --- a/drivers/baseband/turbo_sw/bbdev_turbo_software.c
> +++ b/drivers/baseband/turbo_sw/bbdev_turbo_software.c
> @@ -10,6 +10,7 @@
>  #include <rte_ring.h>
>  #include <rte_kvargs.h>
>  #include <rte_cycles.h>
> +#include <rte_errno.h>
> 
>  #include <rte_bbdev.h>
>  #include <rte_bbdev_pmd.h>
> @@ -302,7 +303,8 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
>  		rte_bbdev_log(ERR,
>  				"Creating queue name for device %u queue
> %u failed",
>  				dev->data->dev_id, q_id);
> -		return -ENAMETOOLONG;
> +		ret = -ENAMETOOLONG;
> +		goto free_q;
>  	}
>  	q->enc_out = rte_zmalloc_socket(name,
>  			((RTE_BBDEV_TURBO_MAX_TB_SIZE >> 3) + 3) * @@
> -311,6 +313,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
>  	if (q->enc_out == NULL) {
>  		rte_bbdev_log(ERR,
>  			"Failed to allocate queue memory for %s", name);
> +		ret = -ENOMEM;
>  		goto free_q;
>  	}
> 
> @@ -322,7 +325,8 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
>  		rte_bbdev_log(ERR,
>  				"Creating queue name for device %u queue
> %u failed",
>  				dev->data->dev_id, q_id);
> -		return -ENAMETOOLONG;
> +		ret = -ENAMETOOLONG;
> +		goto free_q;
>  	}
>  	q->enc_in = rte_zmalloc_socket(name,
>  			(RTE_BBDEV_LDPC_MAX_CB_SIZE >> 3) * sizeof(*q-
> >enc_in), @@ -330,6 +334,7 @@ q_setup(struct rte_bbdev *dev, uint16_t
> q_id,
>  	if (q->enc_in == NULL) {
>  		rte_bbdev_log(ERR,
>  			"Failed to allocate queue memory for %s", name);
> +		ret = -ENOMEM;
>  		goto free_q;
>  	}
> 
> @@ -340,7 +345,8 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
>  		rte_bbdev_log(ERR,
>  				"Creating queue name for device %u queue
> %u failed",
>  				dev->data->dev_id, q_id);
> -		return -ENAMETOOLONG;
> +		ret = -ENAMETOOLONG;
> +		goto free_q;
>  	}
>  	q->ag = rte_zmalloc_socket(name,
>  			RTE_BBDEV_TURBO_MAX_CB_SIZE * 10 * sizeof(*q-
> >ag), @@ -348,6 +354,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
>  	if (q->ag == NULL) {
>  		rte_bbdev_log(ERR,
>  			"Failed to allocate queue memory for %s", name);
> +		ret = -ENOMEM;
>  		goto free_q;
>  	}
> 
> @@ -358,7 +365,8 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
>  		rte_bbdev_log(ERR,
>  				"Creating queue name for device %u queue
> %u failed",
>  				dev->data->dev_id, q_id);
> -		return -ENAMETOOLONG;
> +		ret = -ENAMETOOLONG;
> +		goto free_q;
>  	}
>  	q->code_block = rte_zmalloc_socket(name,
>  			RTE_BBDEV_TURBO_MAX_CB_SIZE * sizeof(*q-
> >code_block), @@ -366,6 +374,7 @@ q_setup(struct rte_bbdev *dev,
> uint16_t q_id,
>  	if (q->code_block == NULL) {
>  		rte_bbdev_log(ERR,
>  			"Failed to allocate queue memory for %s", name);
> +		ret = -ENOMEM;
>  		goto free_q;
>  	}
> 
> @@ -377,7 +386,8 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
>  		rte_bbdev_log(ERR,
>  				"Creating queue name for device %u queue
> %u failed",
>  				dev->data->dev_id, q_id);
> -		return -ENAMETOOLONG;
> +		ret = -ENAMETOOLONG;
> +		goto free_q;
>  	}
>  	q->deint_input = rte_zmalloc_socket(name,
>  			DEINT_INPUT_BUF_SIZE * sizeof(*q->deint_input),
> @@ -385,6 +395,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
>  	if (q->deint_input == NULL) {
>  		rte_bbdev_log(ERR,
>  			"Failed to allocate queue memory for %s", name);
> +		ret = -ENOMEM;
>  		goto free_q;
>  	}
> 
> @@ -396,7 +407,8 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
>  		rte_bbdev_log(ERR,
>  				"Creating queue name for device %u queue
> %u failed",
>  				dev->data->dev_id, q_id);
> -		return -ENAMETOOLONG;
> +		ret = -ENAMETOOLONG;
> +		goto free_q;
>  	}
>  	q->deint_output = rte_zmalloc_socket(NULL,
>  			DEINT_OUTPUT_BUF_SIZE * sizeof(*q-
> >deint_output), @@ -404,6 +416,7 @@ q_setup(struct rte_bbdev *dev,
> uint16_t q_id,
>  	if (q->deint_output == NULL) {
>  		rte_bbdev_log(ERR,
>  			"Failed to allocate queue memory for %s", name);
> +		ret = -ENOMEM;
>  		goto free_q;
>  	}
> 
> @@ -415,7 +428,8 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
>  		rte_bbdev_log(ERR,
>  				"Creating queue name for device %u queue
> %u failed",
>  				dev->data->dev_id, q_id);
> -		return -ENAMETOOLONG;
> +		ret = -ENAMETOOLONG;
> +		goto free_q;
>  	}
>  	q->adapter_output = rte_zmalloc_socket(NULL,
>  			ADAPTER_OUTPUT_BUF_SIZE * sizeof(*q-
> >adapter_output), @@ -423,6 +437,7 @@ q_setup(struct rte_bbdev *dev,
> uint16_t q_id,
>  	if (q->adapter_output == NULL) {
>  		rte_bbdev_log(ERR,
>  			"Failed to allocate queue memory for %s", name);
> +		ret = -ENOMEM;
>  		goto free_q;
>  	}
> 
> @@ -433,12 +448,14 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
>  		rte_bbdev_log(ERR,
>  				"Creating queue name for device %u queue
> %u failed",
>  				dev->data->dev_id, q_id);
> -		return -ENAMETOOLONG;
> +		ret = -ENAMETOOLONG;
> +		goto free_q;
>  	}
>  	q->processed_pkts = rte_ring_create(name, queue_conf-
> >queue_size,
>  			queue_conf->socket, RING_F_SP_ENQ |
> RING_F_SC_DEQ);
>  	if (q->processed_pkts == NULL) {
>  		rte_bbdev_log(ERR, "Failed to create ring for %s", name);
> +		ret = -rte_errno;
>  		goto free_q;
>  	}
> 
> @@ -458,7 +475,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id,
>  	rte_free(q->deint_output);
>  	rte_free(q->adapter_output);
>  	rte_free(q);
> -	return -EFAULT;
> +	return ret;
>  }
> 
>  static const struct rte_bbdev_ops pmd_ops = {
> --
> 2.23.0

Reviewed-By


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [dpdk-dev] [PATCH v2] baseband/turbo_sw: fix memory leak in error path
  2020-10-15 13:45 ` [dpdk-dev] [PATCH v2] " wangyunjian
  2020-10-17  0:22   ` Chautru, Nicolas
@ 2020-10-28 11:29   ` Akhil Goyal
  1 sibling, 0 replies; 6+ messages in thread
From: Akhil Goyal @ 2020-10-28 11:29 UTC (permalink / raw)
  To: wangyunjian, dev; +Cc: nicolas.chautru, jerry.lilijun, xudingke, stable

> Subject: [dpdk-dev] [PATCH v2] baseband/turbo_sw: fix memory leak in error
> path
> 
> From: Yunjian Wang <wangyunjian@huawei.com>
> 
> In q_setup() allocated memory for the queue data, we should free
> it when error happens, otherwise it will lead to memory leak.
> 
> Fixes: b8cfe2c9aed2 ("bb/turbo_sw: add software turbo driver")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---
> v2:
>    fix code styles Chautru Nicolas
Applied to dpdk-next-crypto
Thanks.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-07  9:03 [dpdk-dev] [PATCH] baseband/turbo_sw: fix memory leak in error path wangyunjian
2020-10-07 23:45 ` Chautru, Nicolas
2020-10-15 12:50   ` wangyunjian
2020-10-15 13:45 ` [dpdk-dev] [PATCH v2] " wangyunjian
2020-10-17  0:22   ` Chautru, Nicolas
2020-10-28 11:29   ` Akhil Goyal

DPDK patches and discussions

Archives are clonable:
	git clone --mirror http://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ http://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev


Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/ public-inbox