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 C2BCBA04B5 for ; Thu, 29 Oct 2020 13:18:24 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 2E24ECB63; Thu, 29 Oct 2020 13:18:20 +0100 (CET) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by dpdk.org (Postfix) with ESMTP id 9E2F7CAF8; Thu, 29 Oct 2020 13:18:16 +0100 (CET) Received: from DGGEMM401-HUB.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4CMPbn6w8jz4wsD; Thu, 29 Oct 2020 20:18:13 +0800 (CST) Received: from DGGEMM423-HUB.china.huawei.com (10.1.198.40) by DGGEMM401-HUB.china.huawei.com (10.3.20.209) with Microsoft SMTP Server (TLS) id 14.3.487.0; Thu, 29 Oct 2020 20:18:11 +0800 Received: from DGGEMM533-MBX.china.huawei.com ([169.254.5.167]) by dggemm423-hub.china.huawei.com ([10.1.198.40]) with mapi id 14.03.0487.000; Thu, 29 Oct 2020 20:18:03 +0800 From: wangyunjian To: Thomas Monjalon CC: "dev@dpdk.org" , "ferruh.yigit@intel.com" , "andrew.rybchenko@oktetlabs.ru" , "Lilijun (Jerry)" , xudingke , "stable@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH v2] ethdev: fix data type for port id Thread-Index: AQHWrGbfBrj578R+gUqR3nF3ceqyEamq/D6AgAOEK2A= Date: Thu, 29 Oct 2020 12:18:02 +0000 Message-ID: <34EFBCA9F01B0748BEB6B629CE643AE60DADDBEB@DGGEMM533-MBX.china.huawei.com> References: <1603806082-21484-1-git-send-email-wangyunjian@huawei.com> <3015812.jyVNu9Cn7i@thomas> In-Reply-To: <3015812.jyVNu9Cn7i@thomas> Accept-Language: en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.174.187.156] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-CFilter-Loop: Reflected Subject: Re: [dpdk-stable] [dpdk-dev] [PATCH v2] ethdev: fix data type for port id 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" > -----Original Message----- > From: Thomas Monjalon [mailto:thomas@monjalon.net] > Sent: Tuesday, October 27, 2020 10:29 PM > To: wangyunjian > Cc: dev@dpdk.org; ferruh.yigit@intel.com; andrew.rybchenko@oktetlabs.ru; > Lilijun (Jerry) ; xudingke ; > wangyunjian ; stable@dpdk.org > Subject: Re: [dpdk-dev] [PATCH v2] ethdev: fix data type for port id >=20 > 27/10/2020 14:41, wangyunjian: > > From: Yunjian Wang > > > > The ethdev port id should be 16 bits now. This patch fixes the data > > type of the variable for 'pid', changing from uint32_t to uint16_t. > > > > We also need use RTE_BUILD_BUG_ON() to ensure that > RTE_MAX_ETHPORTS is > > less or equal to UINT16_MAX. >=20 > Actually the need is to check that we have room for an increment after > RTE_MAX_ETHPORTS, meaning RTE_MAX_ETHPORTS < UINT16_MAX. OK. >=20 > > Fixes: 5b7ba31148a8 ("ethdev: add port ownership") > > Cc: stable@dpdk.org > > > > Signed-off-by: Yunjian Wang > > --- > > v2: > > add RTE_BUILD_BUG_ON() check for RTE_MAX_ETHPORTS validity > > --- > > rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id) { > > - uint32_t pid; > > + uint16_t pid; > > > > if (name =3D=3D NULL) { > > RTE_ETHDEV_LOG(ERR, "Null pointer is specified\n"); @@ -4292,6 > > +4292,8 @@ RTE_INIT(eth_dev_init_cb_lists) { > > int i; > > > > + RTE_BUILD_BUG_ON(RTE_MAX_ETHPORTS > UINT16_MAX); >=20 > As explained above, should check >=3D >=20 > This check is global for ethdev. > Please could you move it somewhere else? >=20 >=20 What about following: # git diff diff --git a/lib/librte_eal/freebsd/eal.c b/lib/librte_eal/freebsd/eal.c index ccea60afe7..ff878f4d4d 100644 --- a/lib/librte_eal/freebsd/eal.c +++ b/lib/librte_eal/freebsd/eal.c @@ -672,6 +672,8 @@ rte_eal_init(int argc, char **argv) struct internal_config *internal_conf =3D eal_get_internal_configuration(); =20 + RTE_BUILD_BUG_ON(RTE_MAX_ETHPORTS >=3D UINT16_MAX); + /* checks if the machine is adequate */ if (!rte_cpu_is_supported()) { rte_eal_init_alert("unsupported cpu type."); diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c index 9b579b8200..bd7fb7b5f1 100644 --- a/lib/librte_eal/linux/eal.c +++ b/lib/librte_eal/linux/eal.c @@ -970,6 +970,8 @@ rte_eal_init(int argc, char **argv) struct internal_config *internal_conf =3D eal_get_internal_configuration(); =20 + RTE_BUILD_BUG_ON(RTE_MAX_ETHPORTS >=3D UINT16_MAX); + /* checks if the machine is adequate */ if (!rte_cpu_is_supported()) { rte_eal_init_alert("unsupported cpu type."); diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c index 141f22adb7..27c2ebd114 100644 --- a/lib/librte_eal/windows/eal.c +++ b/lib/librte_eal/windows/eal.c @@ -265,6 +265,8 @@ rte_eal_init(int argc, char **argv) struct internal_config *internal_conf =3D eal_get_internal_configuration(); =20 + RTE_BUILD_BUG_ON(RTE_MAX_ETHPORTS >=3D UINT16_MAX); + rte_eal_log_init(NULL, 0);