DPDK patches and discussions
 help / color / Atom feed
* [dpdk-dev] [PATCH 0/3] fixes for device event
@ 2020-06-03 12:33 wangyunjian
  2020-06-03 12:54 ` wangyunjian
                   ` (3 more replies)
  0 siblings, 4 replies; 20+ messages in thread
From: wangyunjian @ 2020-06-03 12:33 UTC (permalink / raw)
  To: dev; +Cc: jia.guo, jerry.lilijun, xudingke, Yunjian Wang

From: Yunjian Wang <wangyunjian@huawei.com>

This series include three fixes patches for device event.

Yunjian Wang (3):
  eal: fix memory leak when removing event_cb
  eal: fix remove incorrect event_cb
  eal: return error code when failure

 lib/librte_eal/common/eal_common_dev.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

-- 
1.8.3.1



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

* [dpdk-dev]  [PATCH 0/3] fixes for device event
  2020-06-03 12:33 [dpdk-dev] [PATCH 0/3] fixes for device event wangyunjian
@ 2020-06-03 12:54 ` wangyunjian
  2020-06-03 12:54 ` [dpdk-dev] [PATCH 1/3] eal: fix memory leak when removing event_cb wangyunjian
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 20+ messages in thread
From: wangyunjian @ 2020-06-03 12:54 UTC (permalink / raw)
  To: dev; +Cc: jia.guo, jerry.lilijun, xudingke, Yunjian Wang

From: Yunjian Wang <wangyunjian@huawei.com>

This series include three fixes patches for device event.

Yunjian Wang (3):
  eal: fix memory leak when removing event_cb
  eal: fix remove incorrect event_cb
  eal: return error code when failure

 lib/librte_eal/common/eal_common_dev.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

-- 
1.8.3.1



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

* [dpdk-dev] [PATCH 1/3] eal: fix memory leak when removing event_cb
  2020-06-03 12:33 [dpdk-dev] [PATCH 0/3] fixes for device event wangyunjian
  2020-06-03 12:54 ` wangyunjian
@ 2020-06-03 12:54 ` wangyunjian
  2020-06-03 12:55 ` [dpdk-dev] [PATCH 2/3] eal: fix remove incorrect event_cb wangyunjian
  2020-06-03 12:55 ` [dpdk-dev] [PATCH 3/3] " wangyunjian
  3 siblings, 0 replies; 20+ messages in thread
From: wangyunjian @ 2020-06-03 12:54 UTC (permalink / raw)
  To: dev; +Cc: jia.guo, jerry.lilijun, xudingke, Yunjian Wang, stable

From: Yunjian Wang <wangyunjian@huawei.com>

The event_cb->dev_name is not freed when freeing event_cb,
and this causes a memory leak.

Fixes: a753e53d517b ("eal: add device event monitor framework")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
 lib/librte_eal/common/eal_common_dev.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 9e4f09d..4cfdb80 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -526,6 +526,8 @@ static int cmp_dev_name(const struct rte_device *dev, const void *_name)
 		 */
 		if (event_cb->active == 0) {
 			TAILQ_REMOVE(&dev_event_cbs, event_cb, next);
+			if (event_cb->dev_name)
+				free(event_cb->dev_name);
 			free(event_cb);
 			ret++;
 		} else {
-- 
1.8.3.1



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

* [dpdk-dev]  [PATCH 2/3] eal: fix remove incorrect event_cb
  2020-06-03 12:33 [dpdk-dev] [PATCH 0/3] fixes for device event wangyunjian
  2020-06-03 12:54 ` wangyunjian
  2020-06-03 12:54 ` [dpdk-dev] [PATCH 1/3] eal: fix memory leak when removing event_cb wangyunjian
@ 2020-06-03 12:55 ` wangyunjian
  2020-06-12  5:56   ` Jeff Guo
                     ` (4 more replies)
  2020-06-03 12:55 ` [dpdk-dev] [PATCH 3/3] " wangyunjian
  3 siblings, 5 replies; 20+ messages in thread
From: wangyunjian @ 2020-06-03 12:55 UTC (permalink / raw)
  To: dev; +Cc: jia.guo, jerry.lilijun, xudingke, Yunjian Wang, stable

From: Yunjian Wang <wangyunjian@huawei.com>

When the device_name is NULL, it will remove the event_cb directly.
We need to compare the 'cb_fn' and 'cb_arg' at the same time.

Fixes: a753e53d517b ("eal: add device event monitor framework")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
 lib/librte_eal/common/eal_common_dev.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 4cfdb80..6b465bc 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -516,7 +516,12 @@ static int cmp_dev_name(const struct rte_device *dev, const void *_name)
 				    event_cb->cb_arg != cb_arg))
 					continue;
 			}
-		} else if (device_name != NULL) {
+		} else if (device_name == NULL && event_cb->dev_name == NULL) {
+			if (event_cb->cb_fn != cb_fn ||
+			    (cb_arg != (void *)-1 &&
+			    event_cb->cb_arg != cb_arg))
+				continue;
+		} else {
 			continue;
 		}
 
-- 
1.8.3.1



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

* [dpdk-dev]  [PATCH 3/3] eal: return error code when failure
  2020-06-03 12:33 [dpdk-dev] [PATCH 0/3] fixes for device event wangyunjian
                   ` (2 preceding siblings ...)
  2020-06-03 12:55 ` [dpdk-dev] [PATCH 2/3] eal: fix remove incorrect event_cb wangyunjian
@ 2020-06-03 12:55 ` " wangyunjian
  2020-07-02  9:18   ` Jeff Guo
  3 siblings, 1 reply; 20+ messages in thread
From: wangyunjian @ 2020-06-03 12:55 UTC (permalink / raw)
  To: dev; +Cc: jia.guo, jerry.lilijun, xudingke, Yunjian Wang, stable

From: Yunjian Wang <wangyunjian@huawei.com>

Fix return value, using -EAGAIN instead of 0 when the callback is busy
and using -ENOENT instead of 0 when the callback is not found.

Fixes: a753e53d517b ("eal: add device event monitor framework")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
 lib/librte_eal/common/eal_common_dev.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 6b465bc..5f5e333 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -536,9 +536,14 @@ static int cmp_dev_name(const struct rte_device *dev, const void *_name)
 			free(event_cb);
 			ret++;
 		} else {
-			continue;
+			ret = -EAGAIN;
+			break;
 		}
 	}
+	/* this callback is not be registered */
+	if (ret == 0)
+		ret = -ENOENT;
+
 	rte_spinlock_unlock(&dev_event_lock);
 	return ret;
 }
-- 
1.8.3.1



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

* Re: [dpdk-dev] [PATCH 2/3] eal: fix remove incorrect event_cb
  2020-06-03 12:55 ` [dpdk-dev] [PATCH 2/3] eal: fix remove incorrect event_cb wangyunjian
@ 2020-06-12  5:56   ` Jeff Guo
  2020-06-30 11:29     ` wangyunjian
  2020-06-30 11:56   ` [dpdk-dev] [PATCH v2] eal: fix memory leak when removing event_cb wangyunjian
                     ` (3 subsequent siblings)
  4 siblings, 1 reply; 20+ messages in thread
From: Jeff Guo @ 2020-06-12  5:56 UTC (permalink / raw)
  To: wangyunjian, dev; +Cc: jerry.lilijun, xudingke, stable

hi, yunjian

On 6/3/2020 8:55 PM, wangyunjian wrote:
> From: Yunjian Wang <wangyunjian@huawei.com>
>
> When the device_name is NULL, it will remove the event_cb directly.
> We need to compare the 'cb_fn' and 'cb_arg' at the same time.
>
> Fixes: a753e53d517b ("eal: add device event monitor framework")
> Cc: stable@dpdk.org
>
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---
>   lib/librte_eal/common/eal_common_dev.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
> index 4cfdb80..6b465bc 100644
> --- a/lib/librte_eal/common/eal_common_dev.c
> +++ b/lib/librte_eal/common/eal_common_dev.c
> @@ -516,7 +516,12 @@ static int cmp_dev_name(const struct rte_device *dev, const void *_name)
>   				    event_cb->cb_arg != cb_arg))
>   					continue;
>   			}
> -		} else if (device_name != NULL) {
> +		} else if (device_name == NULL && event_cb->dev_name == NULL) {
> +			if (event_cb->cb_fn != cb_fn ||
> +			    (cb_arg != (void *)-1 &&
> +			    event_cb->cb_arg != cb_arg))
> +				continue;
> +		} else {


If we expect flush all event_cb when device_name is NULL, why we should 
check the cb_fn and cb_arg?


>   			continue;
>   		}
>   

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

* Re: [dpdk-dev] [PATCH 2/3] eal: fix remove incorrect event_cb
  2020-06-12  5:56   ` Jeff Guo
@ 2020-06-30 11:29     ` wangyunjian
  0 siblings, 0 replies; 20+ messages in thread
From: wangyunjian @ 2020-06-30 11:29 UTC (permalink / raw)
  To: Jeff Guo, dev; +Cc: Lilijun (Jerry), xudingke, stable



> -----Original Message-----
> From: Jeff Guo [mailto:jia.guo@intel.com]
> Sent: Friday, June 12, 2020 1:56 PM
> 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 2/3] eal: fix remove incorrect event_cb
> 
> hi, yunjian
> 
> On 6/3/2020 8:55 PM, wangyunjian wrote:
> > From: Yunjian Wang <wangyunjian@huawei.com>
> >
> > When the device_name is NULL, it will remove the event_cb directly.
> > We need to compare the 'cb_fn' and 'cb_arg' at the same time.
> >
> > Fixes: a753e53d517b ("eal: add device event monitor framework")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> > ---
> >   lib/librte_eal/common/eal_common_dev.c | 7 ++++++-
> >   1 file changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/lib/librte_eal/common/eal_common_dev.c
> > b/lib/librte_eal/common/eal_common_dev.c
> > index 4cfdb80..6b465bc 100644
> > --- a/lib/librte_eal/common/eal_common_dev.c
> > +++ b/lib/librte_eal/common/eal_common_dev.c
> > @@ -516,7 +516,12 @@ static int cmp_dev_name(const struct rte_device
> *dev, const void *_name)
> >   				    event_cb->cb_arg != cb_arg))
> >   					continue;
> >   			}
> > -		} else if (device_name != NULL) {
> > +		} else if (device_name == NULL && event_cb->dev_name == NULL) {
> > +			if (event_cb->cb_fn != cb_fn ||
> > +			    (cb_arg != (void *)-1 &&
> > +			    event_cb->cb_arg != cb_arg))
> > +				continue;
> > +		} else {
> 
> 
> If we expect flush all event_cb when device_name is NULL, why we should
> check the cb_fn and cb_arg?

Oh, sorry! My mistake, I am wrong to think that this function is used like
rte_intr_callback_register()/rte_intr_callback_unregister().

Please discard it.

Thanks,
Yunjian
> 
> 
> >   			continue;
> >   		}
> >

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

* [dpdk-dev] [PATCH v2] eal: fix memory leak when removing event_cb
  2020-06-03 12:55 ` [dpdk-dev] [PATCH 2/3] eal: fix remove incorrect event_cb wangyunjian
  2020-06-12  5:56   ` Jeff Guo
@ 2020-06-30 11:56   ` wangyunjian
  2020-07-02  9:28     ` Jeff Guo
  2020-07-02 11:46   ` [dpdk-dev] [PATCH v3 0/2] fixes for device event wangyunjian
                     ` (2 subsequent siblings)
  4 siblings, 1 reply; 20+ messages in thread
From: wangyunjian @ 2020-06-30 11:56 UTC (permalink / raw)
  To: dev, jia.guo; +Cc: jerry.lilijun, xudingke, Yunjian Wang, stable

From: Yunjian Wang <wangyunjian@huawei.com>

The event_cb->dev_name is not freed when freeing event_cb,
and this causes a memory leak.

Fixes: a753e53d517b ("eal: add device event monitor framework")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
 lib/librte_eal/common/eal_common_dev.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 9e4f09d..4cfdb80 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -526,6 +526,8 @@ static int cmp_dev_name(const struct rte_device *dev, const void *_name)
 		 */
 		if (event_cb->active == 0) {
 			TAILQ_REMOVE(&dev_event_cbs, event_cb, next);
+			if (event_cb->dev_name)
+				free(event_cb->dev_name);
 			free(event_cb);
 			ret++;
 		} else {
-- 
1.8.3.1



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

* Re: [dpdk-dev] [PATCH 3/3] eal: return error code when failure
  2020-06-03 12:55 ` [dpdk-dev] [PATCH 3/3] " wangyunjian
@ 2020-07-02  9:18   ` Jeff Guo
  2020-07-02 10:43     ` wangyunjian
  0 siblings, 1 reply; 20+ messages in thread
From: Jeff Guo @ 2020-07-02  9:18 UTC (permalink / raw)
  To: wangyunjian, dev; +Cc: jerry.lilijun, xudingke, stable

hi, yunjian

On 6/3/2020 8:55 PM, wangyunjian wrote:
> From: Yunjian Wang <wangyunjian@huawei.com>
>
> Fix return value, using -EAGAIN instead of 0 when the callback is busy
> and using -ENOENT instead of 0 when the callback is not found.
>
> Fixes: a753e53d517b ("eal: add device event monitor framework")
> Cc: stable@dpdk.org
>
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---
>   lib/librte_eal/common/eal_common_dev.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
> index 6b465bc..5f5e333 100644
> --- a/lib/librte_eal/common/eal_common_dev.c
> +++ b/lib/librte_eal/common/eal_common_dev.c
> @@ -536,9 +536,14 @@ static int cmp_dev_name(const struct rte_device *dev, const void *_name)
>   			free(event_cb);
>   			ret++;
>   		} else {
> -			continue;
> +			ret = -EAGAIN;
> +			break;
>   		}
>   	}


Suggest add a blank line here if there will be another version.


> +	/* this callback is not be registered */
> +	if (ret == 0)
> +		ret = -ENOENT;
> +
>   	rte_spinlock_unlock(&dev_event_lock);
>   	return ret;
>   }

Look good and thanks.

Acked-by: Jeff Guo <jia.guo@intel.com>


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

* Re: [dpdk-dev] [PATCH v2] eal: fix memory leak when removing event_cb
  2020-06-30 11:56   ` [dpdk-dev] [PATCH v2] eal: fix memory leak when removing event_cb wangyunjian
@ 2020-07-02  9:28     ` Jeff Guo
  2020-07-02 10:53       ` wangyunjian
  0 siblings, 1 reply; 20+ messages in thread
From: Jeff Guo @ 2020-07-02  9:28 UTC (permalink / raw)
  To: wangyunjian, dev; +Cc: jerry.lilijun, xudingke, stable

hi, yunjian

On 6/30/2020 7:56 PM, wangyunjian wrote:

> From: Yunjian Wang <wangyunjian@huawei.com>
>
> The event_cb->dev_name is not freed when freeing event_cb,
> and this causes a memory leak.
>
> Fixes: a753e53d517b ("eal: add device event monitor framework")
> Cc: stable@dpdk.org
>
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---
>   lib/librte_eal/common/eal_common_dev.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
> index 9e4f09d..4cfdb80 100644
> --- a/lib/librte_eal/common/eal_common_dev.c
> +++ b/lib/librte_eal/common/eal_common_dev.c
> @@ -526,6 +526,8 @@ static int cmp_dev_name(const struct rte_device *dev, const void *_name)
>   		 */
>   		if (event_cb->active == 0) {
>   			TAILQ_REMOVE(&dev_event_cbs, event_cb, next);
> +			if (event_cb->dev_name)
> +				free(event_cb->dev_name);
>   			free(event_cb);
>   			ret++;
>   		} else {


Could you please to check is there another part need to check memory 
leak like that, such as in rte_dev_event_callback_register?


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

* Re: [dpdk-dev] [PATCH 3/3] eal: return error code when failure
  2020-07-02  9:18   ` Jeff Guo
@ 2020-07-02 10:43     ` wangyunjian
  0 siblings, 0 replies; 20+ messages in thread
From: wangyunjian @ 2020-07-02 10:43 UTC (permalink / raw)
  To: Jeff Guo, dev; +Cc: Lilijun (Jerry), xudingke, stable

> -----Original Message-----
> From: Jeff Guo [mailto:jia.guo@intel.com]
> Sent: Thursday, July 2, 2020 5:19 PM
> 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 3/3] eal: return error code when failure
> 
> hi, yunjian
> 
> On 6/3/2020 8:55 PM, wangyunjian wrote:
> > From: Yunjian Wang <wangyunjian@huawei.com>
> >
> > Fix return value, using -EAGAIN instead of 0 when the callback is busy
> > and using -ENOENT instead of 0 when the callback is not found.
> >
> > Fixes: a753e53d517b ("eal: add device event monitor framework")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> > ---
> >   lib/librte_eal/common/eal_common_dev.c | 7 ++++++-
> >   1 file changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/lib/librte_eal/common/eal_common_dev.c
> > b/lib/librte_eal/common/eal_common_dev.c
> > index 6b465bc..5f5e333 100644
> > --- a/lib/librte_eal/common/eal_common_dev.c
> > +++ b/lib/librte_eal/common/eal_common_dev.c
> > @@ -536,9 +536,14 @@ static int cmp_dev_name(const struct rte_device
> *dev, const void *_name)
> >   			free(event_cb);
> >   			ret++;
> >   		} else {
> > -			continue;
> > +			ret = -EAGAIN;
> > +			break;
> >   		}
> >   	}
> 
> 
> Suggest add a blank line here if there will be another version.

Thanks, I will fix it in next version.

Yunjian

> 
> 
> > +	/* this callback is not be registered */
> > +	if (ret == 0)
> > +		ret = -ENOENT;
> > +
> >   	rte_spinlock_unlock(&dev_event_lock);
> >   	return ret;
> >   }
> 
> Look good and thanks.
> 
> Acked-by: Jeff Guo <jia.guo@intel.com>


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

* Re: [dpdk-dev] [PATCH v2] eal: fix memory leak when removing event_cb
  2020-07-02  9:28     ` Jeff Guo
@ 2020-07-02 10:53       ` wangyunjian
  0 siblings, 0 replies; 20+ messages in thread
From: wangyunjian @ 2020-07-02 10:53 UTC (permalink / raw)
  To: Jeff Guo, dev; +Cc: Lilijun (Jerry), xudingke, stable

Hi, Jeff

> -----Original Message-----
> From: Jeff Guo [mailto:jia.guo@intel.com]
> Sent: Thursday, July 2, 2020 5:28 PM
> 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 v2] eal: fix memory leak when removing
> event_cb
> 
> hi, yunjian
> 
> On 6/30/2020 7:56 PM, wangyunjian wrote:
> 
> > From: Yunjian Wang <wangyunjian@huawei.com>
> >
> > The event_cb->dev_name is not freed when freeing event_cb,
> > and this causes a memory leak.
> >
> > Fixes: a753e53d517b ("eal: add device event monitor framework")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> > ---
> >   lib/librte_eal/common/eal_common_dev.c | 2 ++
> >   1 file changed, 2 insertions(+)
> >
> > diff --git a/lib/librte_eal/common/eal_common_dev.c
> b/lib/librte_eal/common/eal_common_dev.c
> > index 9e4f09d..4cfdb80 100644
> > --- a/lib/librte_eal/common/eal_common_dev.c
> > +++ b/lib/librte_eal/common/eal_common_dev.c
> > @@ -526,6 +526,8 @@ static int cmp_dev_name(const struct rte_device
> *dev, const void *_name)
> >   		 */
> >   		if (event_cb->active == 0) {
> >   			TAILQ_REMOVE(&dev_event_cbs, event_cb, next);
> > +			if (event_cb->dev_name)
> > +				free(event_cb->dev_name);
> >   			free(event_cb);
> >   			ret++;
> >   		} else {
> 
> 
> Could you please to check is there another part need to check memory
> leak like that, such as in rte_dev_event_callback_register?

Yes, I have checked and find some same problems. I will also fix them.

Thanks,
Yunjian

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

* [dpdk-dev]  [PATCH v3 0/2] fixes for device event
  2020-06-03 12:55 ` [dpdk-dev] [PATCH 2/3] eal: fix remove incorrect event_cb wangyunjian
  2020-06-12  5:56   ` Jeff Guo
  2020-06-30 11:56   ` [dpdk-dev] [PATCH v2] eal: fix memory leak when removing event_cb wangyunjian
@ 2020-07-02 11:46   ` wangyunjian
  2020-07-02 11:47   ` [dpdk-dev] [PATCH v3 1/2] eal: fix memory leak when removing event_cb wangyunjian
  2020-07-02 11:47   ` [dpdk-dev] [PATCH v3 2/2] eal: return error code when failure wangyunjian
  4 siblings, 0 replies; 20+ messages in thread
From: wangyunjian @ 2020-07-02 11:46 UTC (permalink / raw)
  To: dev; +Cc: jia.guo, jerry.lilijun, xudingke, Yunjian Wang

From: Yunjian Wang <wangyunjian@huawei.com>

v3: modified the format.

This series include two fixes patches for device event.

Yunjian Wang (2):
  eal: fix memory leak when removing event_cb
  eal: return error code when failure

 lib/librte_eal/common/eal_common_dev.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

-- 
1.8.3.1



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

* [dpdk-dev] [PATCH v3 1/2] eal: fix memory leak when removing event_cb
  2020-06-03 12:55 ` [dpdk-dev] [PATCH 2/3] eal: fix remove incorrect event_cb wangyunjian
                     ` (2 preceding siblings ...)
  2020-07-02 11:46   ` [dpdk-dev] [PATCH v3 0/2] fixes for device event wangyunjian
@ 2020-07-02 11:47   ` wangyunjian
  2020-07-03  6:04     ` Jeff Guo
  2020-07-03  7:23     ` [dpdk-dev] [dpdk-stable] " David Marchand
  2020-07-02 11:47   ` [dpdk-dev] [PATCH v3 2/2] eal: return error code when failure wangyunjian
  4 siblings, 2 replies; 20+ messages in thread
From: wangyunjian @ 2020-07-02 11:47 UTC (permalink / raw)
  To: dev; +Cc: jia.guo, jerry.lilijun, xudingke, Yunjian Wang, stable

From: Yunjian Wang <wangyunjian@huawei.com>

The event_cb->dev_name is not freed when freeing event_cb,
and this causes a memory leak.

Fixes: a753e53d517b ("eal: add device event monitor framework")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
 lib/librte_eal/common/eal_common_dev.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 9e4f09d..4cfdb80 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -526,6 +526,8 @@ static int cmp_dev_name(const struct rte_device *dev, const void *_name)
 		 */
 		if (event_cb->active == 0) {
 			TAILQ_REMOVE(&dev_event_cbs, event_cb, next);
+			if (event_cb->dev_name)
+				free(event_cb->dev_name);
 			free(event_cb);
 			ret++;
 		} else {
-- 
1.8.3.1



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

* [dpdk-dev]  [PATCH v3 2/2] eal: return error code when failure
  2020-06-03 12:55 ` [dpdk-dev] [PATCH 2/3] eal: fix remove incorrect event_cb wangyunjian
                     ` (3 preceding siblings ...)
  2020-07-02 11:47   ` [dpdk-dev] [PATCH v3 1/2] eal: fix memory leak when removing event_cb wangyunjian
@ 2020-07-02 11:47   ` wangyunjian
  4 siblings, 0 replies; 20+ messages in thread
From: wangyunjian @ 2020-07-02 11:47 UTC (permalink / raw)
  To: dev; +Cc: jia.guo, jerry.lilijun, xudingke, Yunjian Wang, stable

From: Yunjian Wang <wangyunjian@huawei.com>

Fix return value, using -EAGAIN instead of 0 when the callback is busy
and using -ENOENT instead of 0 when the callback is not found.

Fixes: a753e53d517b ("eal: add device event monitor framework")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
Acked-by: Jeff Guo <jia.guo@intel.com>
---
 lib/librte_eal/common/eal_common_dev.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 4cfdb80..f8df8d4 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -531,9 +531,15 @@ static int cmp_dev_name(const struct rte_device *dev, const void *_name)
 			free(event_cb);
 			ret++;
 		} else {
-			continue;
+			ret = -EAGAIN;
+			break;
 		}
 	}
+
+	/* this callback is not be registered */
+	if (ret == 0)
+		ret = -ENOENT;
+
 	rte_spinlock_unlock(&dev_event_lock);
 	return ret;
 }
-- 
1.8.3.1



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

* Re: [dpdk-dev] [PATCH v3 1/2] eal: fix memory leak when removing event_cb
  2020-07-02 11:47   ` [dpdk-dev] [PATCH v3 1/2] eal: fix memory leak when removing event_cb wangyunjian
@ 2020-07-03  6:04     ` Jeff Guo
  2020-07-03  7:00       ` wangyunjian
  2020-07-03  7:23     ` [dpdk-dev] [dpdk-stable] " David Marchand
  1 sibling, 1 reply; 20+ messages in thread
From: Jeff Guo @ 2020-07-03  6:04 UTC (permalink / raw)
  To: wangyunjian, dev; +Cc: jerry.lilijun, xudingke, stable

hi, yunjian

On 7/2/2020 7:47 PM, wangyunjian wrote:
> From: Yunjian Wang <wangyunjian@huawei.com>
>
> The event_cb->dev_name is not freed when freeing event_cb,
> and this causes a memory leak.
>
> Fixes: a753e53d517b ("eal: add device event monitor framework")
> Cc: stable@dpdk.org
>
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---
>   lib/librte_eal/common/eal_common_dev.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
> index 9e4f09d..4cfdb80 100644
> --- a/lib/librte_eal/common/eal_common_dev.c
> +++ b/lib/librte_eal/common/eal_common_dev.c
> @@ -526,6 +526,8 @@ static int cmp_dev_name(const struct rte_device *dev, const void *_name)
>   		 */
>   		if (event_cb->active == 0) {
>   			TAILQ_REMOVE(&dev_event_cbs, event_cb, next);
> +			if (event_cb->dev_name)
> +				free(event_cb->dev_name);
>   			free(event_cb);
>   			ret++;
>   		} else {


After you check, don't you think the memory leak would not occur in 
rte_dev_event_callback_register when free event_cb? And if you have find 
other same problem, suggest to fix it wholly by this good chance. Thanks.

int
rte_dev_event_callback_register(const char *device_name,
                 rte_dev_event_cb_fn cb_fn,
                 void *cb_arg)
{

error:
     free(event_cb);
     rte_spinlock_unlock(&dev_event_lock);
     return ret;

}


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

* Re: [dpdk-dev] [PATCH v3 1/2] eal: fix memory leak when removing event_cb
  2020-07-03  6:04     ` Jeff Guo
@ 2020-07-03  7:00       ` wangyunjian
  0 siblings, 0 replies; 20+ messages in thread
From: wangyunjian @ 2020-07-03  7:00 UTC (permalink / raw)
  To: Jeff Guo, dev; +Cc: Lilijun (Jerry), xudingke, stable

Hi, Jeff

> -----Original Message-----
> From: Jeff Guo [mailto:jia.guo@intel.com]
> Sent: Friday, July 3, 2020 2:05 PM
> 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 v3 1/2] eal: fix memory leak when removing
> event_cb
> 
> hi, yunjian
> 
> On 7/2/2020 7:47 PM, wangyunjian wrote:
> > From: Yunjian Wang <wangyunjian@huawei.com>
> >
> > The event_cb->dev_name is not freed when freeing event_cb, and this
> > causes a memory leak.
> >
> > Fixes: a753e53d517b ("eal: add device event monitor framework")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> > ---
> >   lib/librte_eal/common/eal_common_dev.c | 2 ++
> >   1 file changed, 2 insertions(+)
> >
> > diff --git a/lib/librte_eal/common/eal_common_dev.c
> > b/lib/librte_eal/common/eal_common_dev.c
> > index 9e4f09d..4cfdb80 100644
> > --- a/lib/librte_eal/common/eal_common_dev.c
> > +++ b/lib/librte_eal/common/eal_common_dev.c
> > @@ -526,6 +526,8 @@ static int cmp_dev_name(const struct rte_device
> *dev, const void *_name)
> >   		 */
> >   		if (event_cb->active == 0) {
> >   			TAILQ_REMOVE(&dev_event_cbs, event_cb, next);
> > +			if (event_cb->dev_name)
> > +				free(event_cb->dev_name);
> >   			free(event_cb);
> >   			ret++;
> >   		} else {
> 
> 
> After you check, don't you think the memory leak would not occur in
> rte_dev_event_callback_register when free event_cb? And if you have find
> other same problem, suggest to fix it wholly by this good chance. Thanks.
> 

Yes, I've confirmed that it's not necessary. The 'event_cb->dev_name' is not allocated
memory on error path in rte_dev_event_callback_register(). But I find the return value
is wrong, when the callback is already exist, will include it in next version.

The similar bugs I found in other codes will be fixed in another patches.

Thanks,
Yunjian

> int
> rte_dev_event_callback_register(const char *device_name,
>                  rte_dev_event_cb_fn cb_fn,
>                  void *cb_arg)
> {
> 
> error:
>      free(event_cb);
>      rte_spinlock_unlock(&dev_event_lock);
>      return ret;
> 
> }


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

* Re: [dpdk-dev] [dpdk-stable] [PATCH v3 1/2] eal: fix memory leak when removing event_cb
  2020-07-02 11:47   ` [dpdk-dev] [PATCH v3 1/2] eal: fix memory leak when removing event_cb wangyunjian
  2020-07-03  6:04     ` Jeff Guo
@ 2020-07-03  7:23     ` " David Marchand
  2020-07-03  7:52       ` wangyunjian
  1 sibling, 1 reply; 20+ messages in thread
From: David Marchand @ 2020-07-03  7:23 UTC (permalink / raw)
  To: wangyunjian; +Cc: dev, Jeff Guo, Lilijun (Jerry), xudingke, dpdk stable

On Thu, Jul 2, 2020 at 1:47 PM wangyunjian <wangyunjian@huawei.com> wrote:
>
> From: Yunjian Wang <wangyunjian@huawei.com>
>
> The event_cb->dev_name is not freed when freeing event_cb,
> and this causes a memory leak.
>
> Fixes: a753e53d517b ("eal: add device event monitor framework")
> Cc: stable@dpdk.org
>
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---
>  lib/librte_eal/common/eal_common_dev.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
> index 9e4f09d..4cfdb80 100644
> --- a/lib/librte_eal/common/eal_common_dev.c
> +++ b/lib/librte_eal/common/eal_common_dev.c
> @@ -526,6 +526,8 @@ static int cmp_dev_name(const struct rte_device *dev, const void *_name)
>                  */
>                 if (event_cb->active == 0) {
>                         TAILQ_REMOVE(&dev_event_cbs, event_cb, next);
> +                       if (event_cb->dev_name)
> +                               free(event_cb->dev_name);

No need for the check, free handles a NULL pointer just fine.

Please, could you update your series/patches status in patchwork?
I am a bit lost at what is superseded or not.


Thanks.

-- 
David Marchand


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

* Re: [dpdk-dev] [dpdk-stable] [PATCH v3 1/2] eal: fix memory leak when removing event_cb
  2020-07-03  7:23     ` [dpdk-dev] [dpdk-stable] " David Marchand
@ 2020-07-03  7:52       ` wangyunjian
  2020-07-03  8:01         ` David Marchand
  0 siblings, 1 reply; 20+ messages in thread
From: wangyunjian @ 2020-07-03  7:52 UTC (permalink / raw)
  To: David Marchand; +Cc: dev, Jeff Guo, Lilijun (Jerry), xudingke, dpdk stable

> -----Original Message-----
> From: David Marchand [mailto:david.marchand@redhat.com]
> Sent: Friday, July 3, 2020 3:23 PM
> To: wangyunjian <wangyunjian@huawei.com>
> Cc: dev <dev@dpdk.org>; Jeff Guo <jia.guo@intel.com>; Lilijun (Jerry)
> <jerry.lilijun@huawei.com>; xudingke <xudingke@huawei.com>; dpdk stable
> <stable@dpdk.org>
> Subject: Re: [dpdk-stable] [dpdk-dev] [PATCH v3 1/2] eal: fix memory leak when
> removing event_cb
> 
> On Thu, Jul 2, 2020 at 1:47 PM wangyunjian <wangyunjian@huawei.com>
> wrote:
> >
> > From: Yunjian Wang <wangyunjian@huawei.com>
> >
> > The event_cb->dev_name is not freed when freeing event_cb, and this
> > causes a memory leak.
> >
> > Fixes: a753e53d517b ("eal: add device event monitor framework")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> > ---
> >  lib/librte_eal/common/eal_common_dev.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/lib/librte_eal/common/eal_common_dev.c
> > b/lib/librte_eal/common/eal_common_dev.c
> > index 9e4f09d..4cfdb80 100644
> > --- a/lib/librte_eal/common/eal_common_dev.c
> > +++ b/lib/librte_eal/common/eal_common_dev.c
> > @@ -526,6 +526,8 @@ static int cmp_dev_name(const struct rte_device
> *dev, const void *_name)
> >                  */
> >                 if (event_cb->active == 0) {
> >                         TAILQ_REMOVE(&dev_event_cbs, event_cb,
> next);
> > +                       if (event_cb->dev_name)
> > +                               free(event_cb->dev_name);
> 
> No need for the check, free handles a NULL pointer just fine.

Thanks for your suggestion, will send the v4 later.

> 
> Please, could you update your series/patches status in patchwork?
> I am a bit lost at what is superseded or not.

My mistake, please discard them.
https://patchwork.dpdk.org/patch/70824/
https://patchwork.dpdk.org/patch/70825/
https://patchwork.dpdk.org/patch/70826/
https://patchwork.dpdk.org/patch/72452/
https://patchwork.dpdk.org/patch/72825/
https://patchwork.dpdk.org/patch/72826/

Thanks,
Yunjian

> 
> 
> Thanks.
> 
> --
> David Marchand


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

* Re: [dpdk-dev] [dpdk-stable] [PATCH v3 1/2] eal: fix memory leak when removing event_cb
  2020-07-03  7:52       ` wangyunjian
@ 2020-07-03  8:01         ` David Marchand
  0 siblings, 0 replies; 20+ messages in thread
From: David Marchand @ 2020-07-03  8:01 UTC (permalink / raw)
  To: wangyunjian; +Cc: dev, Jeff Guo, Lilijun (Jerry), xudingke, dpdk stable

On Fri, Jul 3, 2020 at 9:52 AM wangyunjian <wangyunjian@huawei.com> wrote:
> > Please, could you update your series/patches status in patchwork?
> > I am a bit lost at what is superseded or not.
>
> My mistake, please discard them.
> https://patchwork.dpdk.org/patch/70824/
> https://patchwork.dpdk.org/patch/70825/
> https://patchwork.dpdk.org/patch/70826/
> https://patchwork.dpdk.org/patch/72452/
> https://patchwork.dpdk.org/patch/72825/
> https://patchwork.dpdk.org/patch/72826/

We have been doing this kind of cleanup with Thomas, Ferruh and other
maintainers for some time but this does not scale.
We waste time at figuring out which revision of patches is relevant,
or a duplicate, or a mistake...

I'll do it this time (again), but please register to patchwork and
handle this for your next patches.
Thanks.


-- 
David Marchand


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

end of thread, back to index

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-03 12:33 [dpdk-dev] [PATCH 0/3] fixes for device event wangyunjian
2020-06-03 12:54 ` wangyunjian
2020-06-03 12:54 ` [dpdk-dev] [PATCH 1/3] eal: fix memory leak when removing event_cb wangyunjian
2020-06-03 12:55 ` [dpdk-dev] [PATCH 2/3] eal: fix remove incorrect event_cb wangyunjian
2020-06-12  5:56   ` Jeff Guo
2020-06-30 11:29     ` wangyunjian
2020-06-30 11:56   ` [dpdk-dev] [PATCH v2] eal: fix memory leak when removing event_cb wangyunjian
2020-07-02  9:28     ` Jeff Guo
2020-07-02 10:53       ` wangyunjian
2020-07-02 11:46   ` [dpdk-dev] [PATCH v3 0/2] fixes for device event wangyunjian
2020-07-02 11:47   ` [dpdk-dev] [PATCH v3 1/2] eal: fix memory leak when removing event_cb wangyunjian
2020-07-03  6:04     ` Jeff Guo
2020-07-03  7:00       ` wangyunjian
2020-07-03  7:23     ` [dpdk-dev] [dpdk-stable] " David Marchand
2020-07-03  7:52       ` wangyunjian
2020-07-03  8:01         ` David Marchand
2020-07-02 11:47   ` [dpdk-dev] [PATCH v3 2/2] eal: return error code when failure wangyunjian
2020-06-03 12:55 ` [dpdk-dev] [PATCH 3/3] " wangyunjian
2020-07-02  9:18   ` Jeff Guo
2020-07-02 10:43     ` wangyunjian

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