DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] sched: add parentheses to if clause
@ 2022-02-26 14:55 Weiguo Li
  2022-02-26 17:31 ` Stephen Hemminger
  2022-02-27  5:25 ` [PATCH v2] sched: remove useless malloc in pie data init Weiguo Li
  0 siblings, 2 replies; 10+ messages in thread
From: Weiguo Li @ 2022-02-26 14:55 UTC (permalink / raw)
  To: cristian.dumitrescu; +Cc: wojciechx.liguzinski, dev

Add parentheses to 'if' clause, otherwise will enlarged the
chance of error return.

Fixes: 44c730b0e37971 ("sched: add PIE based congestion management")

Signed-off-by: Weiguo Li <liwg06@foxmail.com>
---
 lib/sched/rte_pie.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/sched/rte_pie.c b/lib/sched/rte_pie.c
index cdb7bab697..51df403a25 100644
--- a/lib/sched/rte_pie.c
+++ b/lib/sched/rte_pie.c
@@ -18,10 +18,10 @@ rte_pie_rt_data_init(struct rte_pie *pie)
 		/* Allocate memory to use the PIE data structure */
 		pie = rte_malloc(NULL, sizeof(struct rte_pie), 0);
 
-		if (pie == NULL)
+		if (pie == NULL) {
 			RTE_LOG(ERR, SCHED, "%s: Memory allocation fails\n", __func__);
-
-		return -1;
+			return -1;
+		}
 	}
 
 	pie->active = 0;
-- 
2.25.1


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

* Re: [PATCH] sched: add parentheses to if clause
  2022-02-26 14:55 [PATCH] sched: add parentheses to if clause Weiguo Li
@ 2022-02-26 17:31 ` Stephen Hemminger
  2022-02-27  5:23   ` Weiguo Li
  2022-02-27  5:25 ` [PATCH v2] sched: remove useless malloc in pie data init Weiguo Li
  1 sibling, 1 reply; 10+ messages in thread
From: Stephen Hemminger @ 2022-02-26 17:31 UTC (permalink / raw)
  To: Weiguo Li; +Cc: cristian.dumitrescu, wojciechx.liguzinski, dev

On Sat, 26 Feb 2022 22:55:30 +0800
Weiguo Li <liwg06@foxmail.com> wrote:

> Add parentheses to 'if' clause, otherwise will enlarged the
> chance of error return.
> 
> Fixes: 44c730b0e37971 ("sched: add PIE based congestion management")
> 
> Signed-off-by: Weiguo Li <liwg06@foxmail.com>
> ---
>  lib/sched/rte_pie.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/sched/rte_pie.c b/lib/sched/rte_pie.c
> index cdb7bab697..51df403a25 100644
> --- a/lib/sched/rte_pie.c
> +++ b/lib/sched/rte_pie.c
> @@ -18,10 +18,10 @@ rte_pie_rt_data_init(struct rte_pie *pie)
>  		/* Allocate memory to use the PIE data structure */
>  		pie = rte_malloc(NULL, sizeof(struct rte_pie), 0);
>  
> -		if (pie == NULL)
> +		if (pie == NULL) {
>  			RTE_LOG(ERR, SCHED, "%s: Memory allocation fails\n", __func__);
> -
> -		return -1;
> +			return -1;
> +		}
>  	}
>  
>  	pie->active = 0;

This will make the test in test_pie.c fail.

The concept of passing NULL to the routine and expecting allocation
is bad idea because the allocated structure is never initialized.

Since rte_pie_rt_data_init(NULL) always returned -1.
It would make more sense to take out the rte_malloc().
And document it.

P.s: the routing should return a negative rte_errno instead of -1
as well.

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

* Re: [PATCH] sched: add parentheses to if clause
  2022-02-26 17:31 ` Stephen Hemminger
@ 2022-02-27  5:23   ` Weiguo Li
  0 siblings, 0 replies; 10+ messages in thread
From: Weiguo Li @ 2022-02-27  5:23 UTC (permalink / raw)
  To: stephen; +Cc: cristian.dumitrescu, wojciechx.liguzinski, dev

On Sat, 26 Feb 2022 09:31:37 -0800, Stephen Hemminger wrote:

> > Add parentheses to 'if' clause, otherwise will enlarged the
> > chance of error return.
> > 
> > Fixes: 44c730b0e37971 ("sched: add PIE based congestion management")
> > 
> > Signed-off-by: Weiguo Li <liwg06@foxmail.com>
> > ---
> >  lib/sched/rte_pie.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/lib/sched/rte_pie.c b/lib/sched/rte_pie.c
> > index cdb7bab697..51df403a25 100644
> > --- a/lib/sched/rte_pie.c
> > +++ b/lib/sched/rte_pie.c
> > @@ -18,10 +18,10 @@ rte_pie_rt_data_init(struct rte_pie *pie)
> >  		/* Allocate memory to use the PIE data structure */
> >  		pie = rte_malloc(NULL, sizeof(struct rte_pie), 0);
> >  
> > -		if (pie == NULL)
> > +		if (pie == NULL) {
> >  			RTE_LOG(ERR, SCHED, "%s: Memory allocation fails\n", __func__);
> > -
> > -		return -1;
> > +			return -1;
> > +		}
> >  	}
> >  
> >  	pie->active = 0;
> 
> This will make the test in test_pie.c fail.
> 
> The concept of passing NULL to the routine and expecting allocation
> is bad idea because the allocated structure is never initialized.
> 
> Since rte_pie_rt_data_init(NULL) always returned -1.
> It would make more sense to take out the rte_malloc().
> And document it.
> 
> P.s: the routing should return a negative rte_errno instead of -1
> as well.
> 

Hi Stephen,

The 'rte_malloc' and null check is really misleading at the first sight...

Thanks for your suggestion!

-Weiguo


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

* [PATCH v2] sched: remove useless malloc in pie data init
  2022-02-26 14:55 [PATCH] sched: add parentheses to if clause Weiguo Li
  2022-02-26 17:31 ` Stephen Hemminger
@ 2022-02-27  5:25 ` Weiguo Li
  2022-03-01  6:07   ` [PATCH v3] " Weiguo Li
  1 sibling, 1 reply; 10+ messages in thread
From: Weiguo Li @ 2022-02-27  5:25 UTC (permalink / raw)
  To: cristian.dumitrescu; +Cc: wojciechx.liguzinski, stephen, dev

'rte_pie_rt_data_init(NULL)' is not expected, and it's ought to
fail when this happen. The malloc inside this funtion didn't work.
So remove the malloc otherwise will lead to a memory leak.

Fixes: 44c730b0e37971 ("sched: add PIE based congestion management")

Signed-off-by: Weiguo Li <liwg06@foxmail.com>
---
v2:
* revise according to Stephen's suggestion.
---
 lib/sched/rte_pie.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/lib/sched/rte_pie.c b/lib/sched/rte_pie.c
index cdb7bab697..eed5c12b54 100644
--- a/lib/sched/rte_pie.c
+++ b/lib/sched/rte_pie.c
@@ -15,13 +15,8 @@ int
 rte_pie_rt_data_init(struct rte_pie *pie)
 {
 	if (pie == NULL) {
-		/* Allocate memory to use the PIE data structure */
-		pie = rte_malloc(NULL, sizeof(struct rte_pie), 0);
-
-		if (pie == NULL)
-			RTE_LOG(ERR, SCHED, "%s: Memory allocation fails\n", __func__);
-
-		return -1;
+		RTE_LOG(ERR, SCHED, "%s: Invalid addr for pie\n", __func__);
+		return -EINVAL;
 	}
 
 	pie->active = 0;
-- 
2.25.1


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

* [PATCH v3] sched: remove useless malloc in pie data init
  2022-02-27  5:25 ` [PATCH v2] sched: remove useless malloc in pie data init Weiguo Li
@ 2022-03-01  6:07   ` Weiguo Li
  2022-03-01 17:08     ` Stephen Hemminger
  0 siblings, 1 reply; 10+ messages in thread
From: Weiguo Li @ 2022-03-01  6:07 UTC (permalink / raw)
  To: cristian.dumitrescu; +Cc: jasvinder.singh, wojciechx.liguzinski, dev

'rte_pie_rt_data_init(NULL)' is not expected, and it's ought to
fail when this happen. The malloc inside the function didn't work.
So remove the malloc otherwise will lead to a memory leak.

Fixes: 44c730b0e37971 ("sched: add PIE based congestion management")

Signed-off-by: Weiguo Li <liwg06@foxmail.com>
---
v3:
* fix typo
v2:
* revise according to Stephen's suggestion.
---
 lib/sched/rte_pie.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/lib/sched/rte_pie.c b/lib/sched/rte_pie.c
index cdb7bab697..eed5c12b54 100644
--- a/lib/sched/rte_pie.c
+++ b/lib/sched/rte_pie.c
@@ -15,13 +15,8 @@ int
 rte_pie_rt_data_init(struct rte_pie *pie)
 {
 	if (pie == NULL) {
-		/* Allocate memory to use the PIE data structure */
-		pie = rte_malloc(NULL, sizeof(struct rte_pie), 0);
-
-		if (pie == NULL)
-			RTE_LOG(ERR, SCHED, "%s: Memory allocation fails\n", __func__);
-
-		return -1;
+		RTE_LOG(ERR, SCHED, "%s: Invalid addr for pie\n", __func__);
+		return -EINVAL;
 	}
 
 	pie->active = 0;
-- 
2.25.1


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

* Re: [PATCH v3] sched: remove useless malloc in pie data init
  2022-03-01  6:07   ` [PATCH v3] " Weiguo Li
@ 2022-03-01 17:08     ` Stephen Hemminger
  2022-03-01 18:00       ` Dumitrescu, Cristian
  0 siblings, 1 reply; 10+ messages in thread
From: Stephen Hemminger @ 2022-03-01 17:08 UTC (permalink / raw)
  To: Weiguo Li; +Cc: cristian.dumitrescu, jasvinder.singh, wojciechx.liguzinski, dev

On Tue,  1 Mar 2022 14:07:56 +0800
Weiguo Li <liwg06@foxmail.com> wrote:

> 'rte_pie_rt_data_init(NULL)' is not expected, and it's ought to
> fail when this happen. The malloc inside the function didn't work.
> So remove the malloc otherwise will lead to a memory leak.
> 
> Fixes: 44c730b0e37971 ("sched: add PIE based congestion management")
> 
> Signed-off-by: Weiguo Li <liwg06@foxmail.com>

Acked-by: Stephen Hemminger <stephen@networkplumber.org>

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

* RE: [PATCH v3] sched: remove useless malloc in pie data init
  2022-03-01 17:08     ` Stephen Hemminger
@ 2022-03-01 18:00       ` Dumitrescu, Cristian
  2022-03-01 18:58         ` [PATCH v4] " Weiguo Li
  2022-03-01 20:32         ` [PATCH v5] " Weiguo Li
  0 siblings, 2 replies; 10+ messages in thread
From: Dumitrescu, Cristian @ 2022-03-01 18:00 UTC (permalink / raw)
  To: Stephen Hemminger, Weiguo Li; +Cc: Singh, Jasvinder, wojciechx.liguzinski, dev



> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: Tuesday, March 1, 2022 5:08 PM
> To: Weiguo Li <liwg06@foxmail.com>
> Cc: Dumitrescu, Cristian <cristian.dumitrescu@intel.com>; Singh, Jasvinder
> <jasvinder.singh@intel.com>; wojciechx.liguzinski@intel.com; dev@dpdk.org
> Subject: Re: [PATCH v3] sched: remove useless malloc in pie data init
> 
> On Tue,  1 Mar 2022 14:07:56 +0800
> Weiguo Li <liwg06@foxmail.com> wrote:
> 
> > 'rte_pie_rt_data_init(NULL)' is not expected, and it's ought to
> > fail when this happen. The malloc inside the function didn't work.
> > So remove the malloc otherwise will lead to a memory leak.
> >
> > Fixes: 44c730b0e37971 ("sched: add PIE based congestion management")
> >
> > Signed-off-by: Weiguo Li <liwg06@foxmail.com>
> 
> Acked-by: Stephen Hemminger <stephen@networkplumber.org>

Hi Li,

I suggest you also replace all the assignments to zero in this function with a memset(0) of the entire structure. I see we set all fields to zero by direct assignment, with the exception of qlen_bytes, which looks like another small issue to me that we could fix here. The memset(0) should work even if later on we might need to set some fields to a non-zero value, as this can be done immediately after the memset(0). Ok with you?

Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>

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

* [PATCH v4] sched: remove useless malloc in pie data init
  2022-03-01 18:00       ` Dumitrescu, Cristian
@ 2022-03-01 18:58         ` Weiguo Li
  2022-03-01 20:32         ` [PATCH v5] " Weiguo Li
  1 sibling, 0 replies; 10+ messages in thread
From: Weiguo Li @ 2022-03-01 18:58 UTC (permalink / raw)
  To: cristian.dumitrescu
  Cc: jasvinder.singh, wojciechx.liguzinski, dev, Stephen Hemminger

'rte_pie_rt_data_init(NULL)' is not expected, and it's ought to
fail when this happen. The malloc inside the function didn't work.
So remove the malloc otherwise will lead to a memory leak.

Fixes: 44c730b0e37971 ("sched: add PIE based congestion management")

Signed-off-by: Weiguo Li <liwg06@foxmail.com>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
v4:
* replace all assignments to zero by a memset.
v3:
* fix typo
v2:
* revise according to Stephen's suggestion.
---
 lib/sched/rte_pie.c | 21 +++------------------
 1 file changed, 3 insertions(+), 18 deletions(-)

diff --git a/lib/sched/rte_pie.c b/lib/sched/rte_pie.c
index cdb7bab697..05a456d7ac 100644
--- a/lib/sched/rte_pie.c
+++ b/lib/sched/rte_pie.c
@@ -15,26 +15,11 @@ int
 rte_pie_rt_data_init(struct rte_pie *pie)
 {
 	if (pie == NULL) {
-		/* Allocate memory to use the PIE data structure */
-		pie = rte_malloc(NULL, sizeof(struct rte_pie), 0);
-
-		if (pie == NULL)
-			RTE_LOG(ERR, SCHED, "%s: Memory allocation fails\n", __func__);
-
-		return -1;
+		RTE_LOG(ERR, SCHED, "%s: Invalid addr for pie\n", __func__);
+		return -EINVAL;
 	}
 
-	pie->active = 0;
-	pie->in_measurement = 0;
-	pie->departed_bytes_count = 0;
-	pie->start_measurement = 0;
-	pie->last_measurement = 0;
-	pie->qlen = 0;
-	pie->avg_dq_time = 0;
-	pie->burst_allowance = 0;
-	pie->qdelay_old = 0;
-	pie->drop_prob = 0;
-	pie->accu_prob = 0;
+	memset(pie, 0, sizeof(*pie));
 
 	return 0;
 }
-- 
2.25.1


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

* [PATCH v5] sched: remove useless malloc in pie data init
  2022-03-01 18:00       ` Dumitrescu, Cristian
  2022-03-01 18:58         ` [PATCH v4] " Weiguo Li
@ 2022-03-01 20:32         ` Weiguo Li
  2022-03-07 18:35           ` Thomas Monjalon
  1 sibling, 1 reply; 10+ messages in thread
From: Weiguo Li @ 2022-03-01 20:32 UTC (permalink / raw)
  To: cristian.dumitrescu; +Cc: jasvinder.singh, dev, Stephen Hemminger

'rte_pie_rt_data_init(NULL)' is not expected, and it's ought to
fail when this happen. The malloc inside the function didn't work.
So remove the malloc otherwise will lead to a memory leak.

Fixes: 44c730b0e37971 ("sched: add PIE based congestion management")

Signed-off-by: Weiguo Li <liwg06@foxmail.com>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
v5:
* fix compile error
v4:
* replace all assignments to zero by a memset.
v3:
* fix typo
v2:
* revise according to Stephen's suggestion.
---
 lib/sched/rte_pie.c | 22 ++++------------------
 1 file changed, 4 insertions(+), 18 deletions(-)

diff --git a/lib/sched/rte_pie.c b/lib/sched/rte_pie.c
index cdb7bab697..d37b79e6dd 100644
--- a/lib/sched/rte_pie.c
+++ b/lib/sched/rte_pie.c
@@ -3,6 +3,7 @@
  */
 
 #include <stdlib.h>
+#include <string.h>
 
 #include "rte_pie.h"
 #include <rte_malloc.h>
@@ -15,26 +16,11 @@ int
 rte_pie_rt_data_init(struct rte_pie *pie)
 {
 	if (pie == NULL) {
-		/* Allocate memory to use the PIE data structure */
-		pie = rte_malloc(NULL, sizeof(struct rte_pie), 0);
-
-		if (pie == NULL)
-			RTE_LOG(ERR, SCHED, "%s: Memory allocation fails\n", __func__);
-
-		return -1;
+		RTE_LOG(ERR, SCHED, "%s: Invalid addr for pie\n", __func__);
+		return -EINVAL;
 	}
 
-	pie->active = 0;
-	pie->in_measurement = 0;
-	pie->departed_bytes_count = 0;
-	pie->start_measurement = 0;
-	pie->last_measurement = 0;
-	pie->qlen = 0;
-	pie->avg_dq_time = 0;
-	pie->burst_allowance = 0;
-	pie->qdelay_old = 0;
-	pie->drop_prob = 0;
-	pie->accu_prob = 0;
+	memset(pie, 0, sizeof(*pie));
 
 	return 0;
 }
-- 
2.25.1


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

* Re: [PATCH v5] sched: remove useless malloc in pie data init
  2022-03-01 20:32         ` [PATCH v5] " Weiguo Li
@ 2022-03-07 18:35           ` Thomas Monjalon
  0 siblings, 0 replies; 10+ messages in thread
From: Thomas Monjalon @ 2022-03-07 18:35 UTC (permalink / raw)
  To: Weiguo Li; +Cc: cristian.dumitrescu, dev, jasvinder.singh, Stephen Hemminger

01/03/2022 21:32, Weiguo Li:
> 'rte_pie_rt_data_init(NULL)' is not expected, and it's ought to
> fail when this happen. The malloc inside the function didn't work.
> So remove the malloc otherwise will lead to a memory leak.
> 
> Fixes: 44c730b0e37971 ("sched: add PIE based congestion management")
> 
> Signed-off-by: Weiguo Li <liwg06@foxmail.com>
> Acked-by: Stephen Hemminger <stephen@networkplumber.org>
> Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
> ---
> v5:
> * fix compile error
> v4:
> * replace all assignments to zero by a memset.
> v3:
> * fix typo
> v2:
> * revise according to Stephen's suggestion.

Applied, thanks.





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

end of thread, other threads:[~2022-03-07 18:35 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-26 14:55 [PATCH] sched: add parentheses to if clause Weiguo Li
2022-02-26 17:31 ` Stephen Hemminger
2022-02-27  5:23   ` Weiguo Li
2022-02-27  5:25 ` [PATCH v2] sched: remove useless malloc in pie data init Weiguo Li
2022-03-01  6:07   ` [PATCH v3] " Weiguo Li
2022-03-01 17:08     ` Stephen Hemminger
2022-03-01 18:00       ` Dumitrescu, Cristian
2022-03-01 18:58         ` [PATCH v4] " Weiguo Li
2022-03-01 20:32         ` [PATCH v5] " Weiguo Li
2022-03-07 18:35           ` Thomas Monjalon

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).