From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4A76D42E3D; Tue, 11 Jul 2023 03:48:59 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 20C7B40C35; Tue, 11 Jul 2023 03:48:59 +0200 (CEST) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 7242D4003C for ; Tue, 11 Jul 2023 03:48:57 +0200 (CEST) Received: from dggpeml100024.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4R0Nxd1Q81ztQr4; Tue, 11 Jul 2023 09:45:57 +0800 (CST) Received: from [10.67.100.224] (10.67.100.224) by dggpeml100024.china.huawei.com (7.185.36.115) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 11 Jul 2023 09:48:54 +0800 Subject: Re: [PATCH] lib/ethdev: sanity check on callback before resource allocation To: Kaiyu Zhang , , , CC: References: <20230711011809.96677-1-squirrel.prog@gmail.com> From: fengchengwen Message-ID: Date: Tue, 11 Jul 2023 09:48:54 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <20230711011809.96677-1-squirrel.prog@gmail.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.100.224] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml100024.china.huawei.com (7.185.36.115) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Please add Cc. Reviewed-by: Chengwen Feng On 2023/7/11 9:18, Kaiyu Zhang wrote: > sanity check is performed after a rte_eth_dev object is allocated. > The object is not freed if the check fails, though in the current > reality this never happens, but it's better programming paradigm > to move the quick check up front to the start of > rte_eth_dev_pci_generic_probe. > > Signed-off-by: Kaiyu Zhang > --- > lib/ethdev/ethdev_pci.h | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/lib/ethdev/ethdev_pci.h b/lib/ethdev/ethdev_pci.h > index 94b8fba5d7..320e3e0093 100644 > --- a/lib/ethdev/ethdev_pci.h > +++ b/lib/ethdev/ethdev_pci.h > @@ -126,12 +126,13 @@ rte_eth_dev_pci_generic_probe(struct rte_pci_device *pci_dev, > struct rte_eth_dev *eth_dev; > int ret; > > + if (*dev_init == NULL) > + return -EINVAL; > + > eth_dev = rte_eth_dev_pci_allocate(pci_dev, private_data_size); > if (!eth_dev) > return -ENOMEM; > > - if (*dev_init == NULL) > - return -EINVAL; > ret = dev_init(eth_dev); > if (ret) > rte_eth_dev_release_port(eth_dev); >