From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id E18EBA04DC for ; Tue, 20 Oct 2020 15:18:55 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BDEE3BABC; Tue, 20 Oct 2020 15:18:54 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by dpdk.org (Postfix) with ESMTP id 0C105BABC for ; Tue, 20 Oct 2020 15:18:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603199930; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=bzLAmDbvswfgmDThgo9nsr8jlnVWd+wF+WYEaIUYPOo=; b=Lr40dKONPPRjl5mTTiXe/HbpRcEtehJT8ktxq/JU0xOZ9EwImh+uWTvnbPL8NMIMt0nTBS NOtSKPE2IEp2eCKZw/iugFNLkbD30HLZmtPCBNwf9ConpKw8S+EtjU6rqnfgWHpZD1AIUt FS9YGVFg1uFreFPZxiNzDzvxExkI1BY= Received: from mail-vs1-f72.google.com (mail-vs1-f72.google.com [209.85.217.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-518-E9lRFwRVMaukAOEYvLN3nA-1; Tue, 20 Oct 2020 09:18:46 -0400 X-MC-Unique: E9lRFwRVMaukAOEYvLN3nA-1 Received: by mail-vs1-f72.google.com with SMTP id q28so640857vsr.20 for ; Tue, 20 Oct 2020 06:18:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bzLAmDbvswfgmDThgo9nsr8jlnVWd+wF+WYEaIUYPOo=; b=D3KUpRUuOLO9Ty/ow5H6QjxDkR83oLqoWOifmFRuArnsROkWOP1wZ5IVgNAQVSBvNw rxw8u6paZv701HWgmVT7EOumF5gVZ0gGzAkDXxuLszy+PRSlAhmJnRfufRXc2tTu6C8u aedJAoAZn5LLSVOfChSOgPEyjbjZYyoVkeYVEUoPYnF2viy5/Kr5WpEtFV+OH1cD8Gub yuHMBVyClyR2Wxp4DWR1YIpyNEJiypINjMcQ+/sTpR2KXdImI1Pk0L1eZq0DwiW19Aog 2+lxKy0VH9G3VM8AhRaEv5cb7ryyYRZNaHo60HLWLyKPL9U1M80T9zLjZfrzamA3gVrL ru8A== X-Gm-Message-State: AOAM5334Yzv3D6fUsXrJVSGP8/3bB1YCkeXg+/mQiLkL6T8c+9XssBOs /U1XAU0zgCMN2G2R6Xs+pq9orVtAF60GjHsF9DGldKcyUSPV2hJatfpHYDgxIt+RmBB5/1Bajj5 TfO1legRn+q6lGMZxUrOcAb8= X-Received: by 2002:a05:6102:5d:: with SMTP id k29mr1399035vsp.17.1603199925891; Tue, 20 Oct 2020 06:18:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjj6lmlKVGA4aDZairu9PpDwlrQQ13kCY+R1Kwo+mP0yjSSHeVXRkCmKp53d3Je18KaXYnD32+gVNP/2uefOI= X-Received: by 2002:a05:6102:5d:: with SMTP id k29mr1398998vsp.17.1603199925633; Tue, 20 Oct 2020 06:18:45 -0700 (PDT) MIME-Version: 1.0 References: <3b5329802b1628466e4984de4bde8ac8b6e11508.1593768308.git.wangyunjian@huawei.com> In-Reply-To: <3b5329802b1628466e4984de4bde8ac8b6e11508.1593768308.git.wangyunjian@huawei.com> From: David Marchand Date: Tue, 20 Oct 2020 15:18:34 +0200 Message-ID: To: wangyunjian , Jeff Guo Cc: dev , "Lilijun (Jerry)" , xudingke , dpdk stable Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dmarchan@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Subject: Re: [dpdk-stable] [dpdk-dev] [PATCH v4 3/3] eal: fix a wrong returned value when callback exists X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" On Fri, Jul 3, 2020 at 11:47 AM wangyunjian wrote: > > From: Yunjian Wang > > 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 > --- > 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