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 B464EA04DC; Tue, 20 Oct 2020 15:18:52 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 26746BAAA; Tue, 20 Oct 2020 15:18:51 +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 BF190BAA8 for ; Tue, 20 Oct 2020 15:18:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603199928; 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=QJme/jvz5Eu7BG6lKFSbz71BuDeaOXN1QXsRMhpcUNNtO3IrfSJw0TZWdd+z9hNnq6eGJL MFvcAODwPnH0xnlRA88GCZF/FinDi8E8yp2cHMRODPc533QfdaTrVuPjjWdjWv43DhlPNF QcbLhJrJbjQpUzRB4sT90FyFjSnQ2dc= Received: from mail-vs1-f71.google.com (mail-vs1-f71.google.com [209.85.217.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-66-C9eGNR43M7WRtEdfY47h5A-1; Tue, 20 Oct 2020 09:18:46 -0400 X-MC-Unique: C9eGNR43M7WRtEdfY47h5A-1 Received: by mail-vs1-f71.google.com with SMTP id y196so639974vsc.16 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=i0fx1fyD8oQO9DUUDEFYYKUSKxv5YgRd+2iW/awauC2vbnqCCSHy5gNbd+hONNSauI ehsoVhqMXTsuAD1B7+jpJsdBv7O+9oIGXWSeVxc5yRLpsqwyUNlJ+/EzURWVUDMSWGkF 2Gs9JMMd0mlWeXk7npLkpjYZ73UzCMK0MiooloZmrq3GP3cYBnFmxHKd0P5D/Bag+gm8 Xj4mYpuRz+1KfS1AqqtTnkrrRMFrLks8JKWpppPfwJ7WlsiidmLc9RTaPE9Q3QRVGEoo MUbh+YNspjmrIAFoxbusSJPrIYWCNKaj/ijRtTe7oeS5O3RKdxeyv0ysmzYZtiLLW/CM QTNw== X-Gm-Message-State: AOAM532vSMadV8M4dkPGbBohZgQqR5upyTI4NdD7WdWQtpx9i7KSBwwa sSH/Oy3trOpGIfcNpiYb2KPPQikagLhDCfJUhny4gXGk1At1gyidYsYetuK/UuM7tuxCLkeIJlw 9iPOU6Ruu/OInCg4faOY= X-Received: by 2002:a05:6102:5d:: with SMTP id k29mr1399034vsp.17.1603199925884; 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-dev] [dpdk-stable] [PATCH v4 3/3] eal: fix a wrong returned value when callback exists X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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