From: Yunjian Wang <wangyunjian@huawei.com> This series include three fixes patches for device event. --- v4: * add fix a wrong returned value * remove redundant check suggested by David Marchand v3: * modified the format. Yunjian Wang (3): eal: fix memory leak when removing event_cb eal: return error code when failure eal: fix a wrong returned value when callback exists lib/librte_eal/common/eal_common_dev.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) -- 1.8.3.1
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 | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index 9e4f09d..363a2ca 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -526,6 +526,7 @@ 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); + free(event_cb->dev_name); free(event_cb); ret++; } else { -- 1.8.3.1
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 Acked-by: Jeff Guo <jia.guo@intel.com> Signed-off-by: Yunjian Wang <wangyunjian@huawei.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 363a2ca..d990bfd 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -530,9 +530,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
From: Yunjian Wang <wangyunjian@huawei.com> We should return an error value, when the callback is already exist. 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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index d990bfd..2a097aa 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -431,7 +431,7 @@ static int cmp_dev_name(const struct rte_device *dev, const void *_name) void *cb_arg) { struct dev_event_callback *event_cb; - int ret; + int ret = 0; if (!cb_fn) return -EINVAL; @@ -484,7 +484,7 @@ static int cmp_dev_name(const struct rte_device *dev, const void *_name) } rte_spinlock_unlock(&dev_event_lock); - return 0; + return ret; error: free(event_cb); rte_spinlock_unlock(&dev_event_lock); -- 1.8.3.1
Ping for review.
Thanks,
Yunjian
> -----Original Message-----
> From: wangyunjian
> Sent: Friday, July 3, 2020 5:46 PM
> To: dev@dpdk.org
> Cc: jia.guo@intel.com; Lilijun (Jerry) <jerry.lilijun@huawei.com>; xudingke
> <xudingke@huawei.com>; wangyunjian <wangyunjian@huawei.com>;
> stable@dpdk.org
> Subject: [dpdk-dev] [PATCH v4 1/3] eal: fix memory leak when removing
> event_cb
>
> 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 | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/lib/librte_eal/common/eal_common_dev.c
> b/lib/librte_eal/common/eal_common_dev.c
> index 9e4f09d..363a2ca 100644
> --- a/lib/librte_eal/common/eal_common_dev.c
> +++ b/lib/librte_eal/common/eal_common_dev.c
> @@ -526,6 +526,7 @@ 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);
> + free(event_cb->dev_name);
> free(event_cb);
> ret++;
> } else {
> --
> 1.8.3.1
>
hi, yunjian
The patch seems no problem, but when you update your patch, please add
other guys who had comment on your patch and maintainer to see if they have
other opinion, and --in-reply-to is also helpful for patch review, thanks.
On 7/29/2020 7:47 PM, wangyunjian wrote:
> Ping for review.
>
> Thanks,
> Yunjian
>
>> -----Original Message-----
>> From: wangyunjian
>> Sent: Friday, July 3, 2020 5:46 PM
>> To: dev@dpdk.org
>> Cc: jia.guo@intel.com; Lilijun (Jerry) <jerry.lilijun@huawei.com>; xudingke
>> <xudingke@huawei.com>; wangyunjian <wangyunjian@huawei.com>;
>> stable@dpdk.org
>> Subject: [dpdk-dev] [PATCH v4 1/3] eal: fix memory leak when removing
>> event_cb
>>
>> 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 | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/lib/librte_eal/common/eal_common_dev.c
>> b/lib/librte_eal/common/eal_common_dev.c
>> index 9e4f09d..363a2ca 100644
>> --- a/lib/librte_eal/common/eal_common_dev.c
>> +++ b/lib/librte_eal/common/eal_common_dev.c
>> @@ -526,6 +526,7 @@ 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);
>> + free(event_cb->dev_name);
>> free(event_cb);
>> ret++;
>> } else {
>> --
>> 1.8.3.1
Acked-by: Jeff Guo <jia.guo@intel.com>
Hi, Ferruh Yigit & David Marchand
Could you please give any suggestion?
Thanks,
Yunjian
> -----Original Message-----
> From: wangyunjian
> Sent: Friday, July 3, 2020 5:44 PM
> To: dev@dpdk.org
> Cc: jia.guo@intel.com; Lilijun (Jerry) <jerry.lilijun@huawei.com>; xudingke
> <xudingke@huawei.com>; wangyunjian <wangyunjian@huawei.com>
> Subject: [dpdk-dev] [PATCH v4 0/3] fixes for device event
>
> From: Yunjian Wang <wangyunjian@huawei.com>
>
> This series include three fixes patches for device event.
>
> ---
> v4:
> * add fix a wrong returned value
> * remove redundant check suggested by David Marchand
>
> v3:
> * modified the format.
>
> Yunjian Wang (3):
> eal: fix memory leak when removing event_cb
> eal: return error code when failure
> eal: fix a wrong returned value when callback exists
>
> lib/librte_eal/common/eal_common_dev.c | 13 ++++++++++---
> 1 file changed, 10 insertions(+), 3 deletions(-)
>
> --
> 1.8.3.1
>
On Fri, Jul 3, 2020 at 11:47 AM wangyunjian <wangyunjian@huawei.com> wrote: > > From: Yunjian Wang <wangyunjian@huawei.com> > > We should return an error value, when the callback is already exist. > > 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 | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c > index d990bfd..2a097aa 100644 > --- a/lib/librte_eal/common/eal_common_dev.c > +++ b/lib/librte_eal/common/eal_common_dev.c > @@ -431,7 +431,7 @@ static int cmp_dev_name(const struct rte_device *dev, const void *_name) > void *cb_arg) > { > struct dev_event_callback *event_cb; > - int ret; > + int ret = 0; > > if (!cb_fn) > return -EINVAL; > @@ -484,7 +484,7 @@ static int cmp_dev_name(const struct rte_device *dev, const void *_name) > } > > rte_spinlock_unlock(&dev_event_lock); > - return 0; > + return ret; > error: > free(event_cb); > rte_spinlock_unlock(&dev_event_lock); > -- > 1.8.3.1 A simpler fix is to directly jump to the error label. This has the advantage of having all errors go through a single cleanup code: diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index 9e4f09d83e..fa47074b0b 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -480,7 +480,9 @@ rte_dev_event_callback_register(const char *device_name, RTE_LOG(ERR, EAL, "The callback is already exist, no need " "to register again.\n"); + event_cb = NULL; ret = -EEXIST; + goto error; } rte_spinlock_unlock(&dev_event_lock); What do you think? -- David Marchand
> -----Original Message----- > From: David Marchand [mailto:david.marchand@redhat.com] > Sent: Tuesday, October 20, 2020 9:19 PM > To: wangyunjian <wangyunjian@huawei.com>; Jeff Guo <jia.guo@intel.com> > Cc: dev <dev@dpdk.org>; Lilijun (Jerry) <jerry.lilijun@huawei.com>; xudingke > <xudingke@huawei.com>; dpdk stable <stable@dpdk.org> > Subject: Re: [dpdk-stable] [dpdk-dev] [PATCH v4 3/3] eal: fix a wrong returned > value when callback exists > > On Fri, Jul 3, 2020 at 11:47 AM wangyunjian <wangyunjian@huawei.com> > wrote: > > > > From: Yunjian Wang <wangyunjian@huawei.com> > > > > We should return an error value, when the callback is already exist. > > > > 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 | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/lib/librte_eal/common/eal_common_dev.c > > b/lib/librte_eal/common/eal_common_dev.c > > index d990bfd..2a097aa 100644 > > --- a/lib/librte_eal/common/eal_common_dev.c > > +++ b/lib/librte_eal/common/eal_common_dev.c > > @@ -431,7 +431,7 @@ static int cmp_dev_name(const struct rte_device > *dev, const void *_name) > > void *cb_arg) { > > struct dev_event_callback *event_cb; > > - int ret; > > + int ret = 0; > > > > if (!cb_fn) > > return -EINVAL; > > @@ -484,7 +484,7 @@ static int cmp_dev_name(const struct rte_device > *dev, const void *_name) > > } > > > > rte_spinlock_unlock(&dev_event_lock); > > - return 0; > > + return ret; > > error: > > free(event_cb); > > rte_spinlock_unlock(&dev_event_lock); > > -- > > 1.8.3.1 > > A simpler fix is to directly jump to the error label. > This has the advantage of having all errors go through a single cleanup code: > > diff --git a/lib/librte_eal/common/eal_common_dev.c > b/lib/librte_eal/common/eal_common_dev.c > index 9e4f09d83e..fa47074b0b 100644 > --- a/lib/librte_eal/common/eal_common_dev.c > +++ b/lib/librte_eal/common/eal_common_dev.c > @@ -480,7 +480,9 @@ rte_dev_event_callback_register(const char > *device_name, > RTE_LOG(ERR, EAL, > "The callback is already exist, no need " > "to register again.\n"); > + event_cb = NULL; > ret = -EEXIST; > + goto error; > } > > rte_spinlock_unlock(&dev_event_lock); > > What do you think? Agree, I will update it in next version. Yunjian > > > -- > David Marchand
From: Yunjian Wang <wangyunjian@huawei.com> This series include three fixes patches for device event. --- v5: * update patch 3/3 code styles suggested by David Marchand v4: * add fix a wrong returned value * remove redundant check suggested by David Marchand v3: * modified the format. Yunjian Wang (3): eal: fix memory leak when removing event_cb eal: return error code when failure eal: fix a wrong returned value when callback exists lib/librte_eal/common/eal_common_dev.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) -- 2.23.0
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> Acked-by: Jeff Guo <jia.guo@intel.com> --- lib/librte_eal/common/eal_common_dev.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index 9e4f09d83e..363a2ca95e 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -526,6 +526,7 @@ rte_dev_event_callback_unregister(const char *device_name, */ if (event_cb->active == 0) { TAILQ_REMOVE(&dev_event_cbs, event_cb, next); + free(event_cb->dev_name); free(event_cb); ret++; } else { -- 2.23.0
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 363a2ca95e..d990bfd20d 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -530,9 +530,15 @@ rte_dev_event_callback_unregister(const char *device_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; } -- 2.23.0
From: Yunjian Wang <wangyunjian@huawei.com> We should return an error value, when the callback is already exist. Fixes: a753e53d517b ("eal: add device event monitor framework") Cc: stable@dpdk.org Signed-off-by: Yunjian Wang <wangyunjian@huawei.com> Suggested-by: David Marchand <david.marchand@6wind.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 d990bfd20d..8a3bd3100a 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -480,7 +480,9 @@ rte_dev_event_callback_register(const char *device_name, RTE_LOG(ERR, EAL, "The callback is already exist, no need " "to register again.\n"); + event_cb = NULL; ret = -EEXIST; + goto error; } rte_spinlock_unlock(&dev_event_lock); -- 2.23.0
On Wed, Oct 21, 2020 at 1:19 PM wangyunjian <wangyunjian@huawei.com> 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 This API is experimental, its description is vague enough and we can change it in the current release. But I see this as a change in behavior for existing users, not a fix and I would not backport it. Opinions? > > 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 363a2ca95e..d990bfd20d 100644 > --- a/lib/librte_eal/common/eal_common_dev.c > +++ b/lib/librte_eal/common/eal_common_dev.c > @@ -530,9 +530,15 @@ rte_dev_event_callback_unregister(const char *device_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; > } > -- > 2.23.0 > -- David Marchand
On Wed, Oct 21, 2020 at 1:20 PM wangyunjian <wangyunjian@huawei.com> wrote:
>
> From: Yunjian Wang <wangyunjian@huawei.com>
>
> We should return an error value, when the callback is already exist.
>
> Fixes: a753e53d517b ("eal: add device event monitor framework")
> Cc: stable@dpdk.org
Same question as for the previous patch, should we backport this?
--
David Marchand
> -----Original Message----- > From: David Marchand [mailto:david.marchand@redhat.com] > Sent: Thursday, October 22, 2020 8:52 PM > To: wangyunjian <wangyunjian@huawei.com> > Cc: dev <dev@dpdk.org>; Jeff Guo <jia.guo@intel.com>; Jerin Jacob > Kollanukkaran <jerinj@marvell.com>; Lilijun (Jerry) <jerry.lilijun@huawei.com>; > xudingke <xudingke@huawei.com>; dpdk stable <stable@dpdk.org>; Kevin > Traynor <ktraynor@redhat.com>; Luca Boccassi <bluca@debian.org> > Subject: Re: [dpdk-dev] [PATCH v5 2/3] eal: return error code when failure > > On Wed, Oct 21, 2020 at 1:19 PM wangyunjian <wangyunjian@huawei.com> > 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 > > This API is experimental, its description is vague enough and we can change it > in the current release. > But I see this as a change in behavior for existing users, not a fix and I would > not backport it. > > Opinions? Agree, not backport it. Yunjian > > > > > > 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 363a2ca95e..d990bfd20d 100644 > > --- a/lib/librte_eal/common/eal_common_dev.c > > +++ b/lib/librte_eal/common/eal_common_dev.c > > @@ -530,9 +530,15 @@ rte_dev_event_callback_unregister(const char > *device_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; > > } > > -- > > 2.23.0 > > > > > -- > David Marchand
> -----Original Message----- > From: David Marchand [mailto:david.marchand@redhat.com] > Sent: Thursday, October 22, 2020 8:55 PM > To: wangyunjian <wangyunjian@huawei.com> > Cc: dev <dev@dpdk.org>; Jeff Guo <jia.guo@intel.com>; Jerin Jacob > Kollanukkaran <jerinj@marvell.com>; Lilijun (Jerry) <jerry.lilijun@huawei.com>; > xudingke <xudingke@huawei.com>; dpdk stable <stable@dpdk.org>; Kevin > Traynor <ktraynor@redhat.com>; Luca Boccassi <bluca@debian.org> > Subject: Re: [dpdk-dev] [PATCH v5 3/3] eal: fix a wrong returned value when > callback exists > > On Wed, Oct 21, 2020 at 1:20 PM wangyunjian <wangyunjian@huawei.com> > wrote: > > > > From: Yunjian Wang <wangyunjian@huawei.com> > > > > We should return an error value, when the callback is already exist. > > > > Fixes: a753e53d517b ("eal: add device event monitor framework") > > Cc: stable@dpdk.org > > Same question as for the previous patch, should we backport this? Agree, not backport it. Yunjian > > > -- > David Marchand
On Wed, Oct 21, 2020 at 1:18 PM wangyunjian <wangyunjian@huawei.com> wrote:
>
> From: Yunjian Wang <wangyunjian@huawei.com>
>
> This series include three fixes patches for device event.
For the series,
Acked-by: David Marchand <david.marchand@redhat.com>
Applied, thanks.
--
David Marchand