All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Marchand <david.marchand@redhat.com>
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-dev] [dpdk-stable] [PATCH v4 3/3] eal: fix a wrong returned value when callback exists
Date: Tue, 20 Oct 2020 15:18:34 +0200	[thread overview]
Message-ID: <CAJFAV8zDUApRAYm_04XUXDg-4TeMeR97V+5rynSh7B8KeRkctw@mail.gmail.com> (raw)
In-Reply-To: <3b5329802b1628466e4984de4bde8ac8b6e11508.1593768308.git.wangyunjian@huawei.com>

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


  reply	other threads:[~2020-10-20 13:18 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-03  9:44 [dpdk-dev] [PATCH v4 0/3] fixes for device event wangyunjian
2020-07-03  9:46 ` [dpdk-dev] [PATCH v4 1/3] eal: fix memory leak when removing event_cb wangyunjian
2020-07-29 11:47   ` wangyunjian
2020-07-30  2:57     ` Jeff Guo
2020-07-03  9:46 ` [dpdk-dev] [PATCH v4 2/3] eal: return error code when failure wangyunjian
2020-07-03  9:46 ` [dpdk-dev] [PATCH v4 3/3] eal: fix a wrong returned value when callback exists wangyunjian
2020-10-20 13:18   ` David Marchand [this message]
2020-10-20 14:31     ` [dpdk-dev] [dpdk-stable] " wangyunjian
2020-09-03  3:33 ` [dpdk-dev] [PATCH v4 0/3] fixes for device event wangyunjian
2020-10-21 11:18 ` [dpdk-dev] [PATCH v5 " wangyunjian
2020-10-21 11:19   ` [dpdk-dev] [PATCH v5 1/3] eal: fix memory leak when removing event_cb wangyunjian
2020-10-21 11:19   ` [dpdk-dev] [PATCH v5 2/3] eal: return error code when failure wangyunjian
2020-10-22 12:51     ` David Marchand
2020-10-23  9:05       ` wangyunjian
2020-10-21 11:19   ` [dpdk-dev] [PATCH v5 3/3] eal: fix a wrong returned value when callback exists wangyunjian
2020-10-22 12:55     ` David Marchand
2020-10-23  9:05       ` wangyunjian
2020-10-23 11:37   ` [dpdk-dev] [PATCH v5 0/3] fixes for device event David Marchand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAJFAV8zDUApRAYm_04XUXDg-4TeMeR97V+5rynSh7B8KeRkctw@mail.gmail.com \
    --to=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=jerry.lilijun@huawei.com \
    --cc=jia.guo@intel.com \
    --cc=stable@dpdk.org \
    --cc=wangyunjian@huawei.com \
    --cc=xudingke@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.