From patchwork Wed Jun 3 12:54:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunjian Wang X-Patchwork-Id: 70824 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7F6FEA04A2; Wed, 3 Jun 2020 14:55:10 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 25F621D450; Wed, 3 Jun 2020 14:55:10 +0200 (CEST) Received: from huawei.com (szxga06-in.huawei.com [45.249.212.32]) by dpdk.org (Postfix) with ESMTP id 6E8501D15A; Wed, 3 Jun 2020 14:55:08 +0200 (CEST) Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 9725BDB7EE407B995336; Wed, 3 Jun 2020 20:55:06 +0800 (CST) Received: from localhost (10.173.251.152) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Wed, 3 Jun 2020 20:54:56 +0800 From: wangyunjian To: CC: , , , Yunjian Wang , Date: Wed, 3 Jun 2020 20:54:55 +0800 Message-ID: X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.173.251.152] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH 1/3] eal: fix memory leak when removing event_cb 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" From: Yunjian Wang 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 --- 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 { From patchwork Wed Jun 3 12:55:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunjian Wang X-Patchwork-Id: 70825 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id AD7C3A04A2; Wed, 3 Jun 2020 14:55:17 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 848C81D516; Wed, 3 Jun 2020 14:55:17 +0200 (CEST) Received: from huawei.com (szxga04-in.huawei.com [45.249.212.190]) by dpdk.org (Postfix) with ESMTP id 7FA1E1D15A; Wed, 3 Jun 2020 14:55:15 +0200 (CEST) Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 0CDE52452BFD2817CED7; Wed, 3 Jun 2020 20:55:15 +0800 (CST) Received: from localhost (10.173.251.152) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.487.0; Wed, 3 Jun 2020 20:55:05 +0800 From: wangyunjian To: CC: , , , Yunjian Wang , Date: Wed, 3 Jun 2020 20:55:04 +0800 Message-ID: X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.173.251.152] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH 2/3] eal: fix remove incorrect event_cb 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" From: Yunjian Wang 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 --- 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; } From patchwork Wed Jun 3 12:55:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunjian Wang X-Patchwork-Id: 70826 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B0F58A04A2; Wed, 3 Jun 2020 14:55:27 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E84641D546; Wed, 3 Jun 2020 14:55:25 +0200 (CEST) Received: from huawei.com (szxga04-in.huawei.com [45.249.212.190]) by dpdk.org (Postfix) with ESMTP id ADBE31D536; Wed, 3 Jun 2020 14:55:23 +0200 (CEST) Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id AB8CB499995F7C18C301; Wed, 3 Jun 2020 20:55:21 +0800 (CST) Received: from localhost (10.173.251.152) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Wed, 3 Jun 2020 20:55:15 +0800 From: wangyunjian To: CC: , , , Yunjian Wang , Date: Wed, 3 Jun 2020 20:55:14 +0800 Message-ID: <65433c2a9efdb47b1c9dba63d9bd1cb160e08097.1591186247.git.wangyunjian@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.173.251.152] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH 3/3] eal: return error code when failure 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" From: Yunjian Wang 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 Acked-by: Jeff Guo --- 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; }