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 0012BA0521 for ; Wed, 4 Nov 2020 04:27:08 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C0171BE7F; Wed, 4 Nov 2020 04:27:07 +0100 (CET) Received: from mail-ot1-f67.google.com (mail-ot1-f67.google.com [209.85.210.67]) by dpdk.org (Postfix) with ESMTP id AB6C2BE63 for ; Wed, 4 Nov 2020 04:27:04 +0100 (CET) Received: by mail-ot1-f67.google.com with SMTP id n15so18066801otl.8 for ; Tue, 03 Nov 2020 19:27:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=QQVSDbbMq0HsrK/P7/1vAdF8x5rTNMIQ59YZfnIKOqM=; b=hpJCqw8dS2kUjYBQeD4pF78zOkmSnFmycWiPY///McS+itv9sJnzsuiS4+HkBpsdEW Frc7X7sMcSA1C4K3/nYm+n8TeIfU1fK1Fwc6hcbK5j7bdM7ivDJ78AjJFaYsIwZ9PrWj HZRWTJzNRpZvDtDVLnWEjDD2HRD3oZ9uKgnIE= 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=QQVSDbbMq0HsrK/P7/1vAdF8x5rTNMIQ59YZfnIKOqM=; b=F2xI7igjfFzZcZ9mtRYRoLIh2X1wajpq1W62NR+wel9LYfLI51KuOM4w8i+/G1f2Z3 0XwRBEpRQTGgqPP5T1Oc64PHosdWwrxwIbEvZgZLR83AlYQLCoASLO9jubeRya+7mLw4 Et9tXcAhgM+6pNfAIW2ZH9cLr1reSJM3Ey1Bp0U9/X+cRk7ZV0yQxU1SLLzvZk6ehuBM gXLq/gUBvS8xrOp5iz5n5l1Vy96fIzCja5HUAWZUwcNbyytG2wfT5w737RhSD8zkPiuy xzqR8tJJbbUlpBotNrNOySXd3LU46WIhLSYf1BzRFYE5IMNPOo3u2UKOkmN6ynK2+wBY z3Vw== X-Gm-Message-State: AOAM532aTbG/n1XBGDfKHJcsFCqlbzdAeHPRY+Jo9hnrwtBPgEoJrvW+ qKi3jrD8gXQQNC9FEyjD/wdHlhYOO4jOj8RfC1Yg2Q== X-Google-Smtp-Source: ABdhPJwhNrVULgwWNokKmCeIlWtgnQT8joEoT883SeCviSFSThvtqpHj1BUdH/xFS9c0Ra0Yjxq+jiiehnZEGz13Op8= X-Received: by 2002:a9d:6317:: with SMTP id q23mr16386495otk.95.1604460422582; Tue, 03 Nov 2020 19:27:02 -0800 (PST) MIME-Version: 1.0 References: <1604308702-7744-1-git-send-email-wangyunjian@huawei.com> <1604458677-34696-1-git-send-email-wangyunjian@huawei.com> In-Reply-To: <1604458677-34696-1-git-send-email-wangyunjian@huawei.com> From: Ajit Khaparde Date: Tue, 3 Nov 2020 19:26:46 -0800 Message-ID: To: wangyunjian Cc: dpdk-dev , Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko , Stephen Hemminger , "Lilijun (Jerry)" , xudingke , dpdk stable Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: Re: [dpdk-stable] [dpdk-dev] [PATCH v4] 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" On Tue, Nov 3, 2020 at 6:58 PM wangyunjian wrote: > > From: Yunjian Wang > > The ethdev port id is 16 bits now. This patch fixes the data type > of the variable for 'pid', which changing from uint32_t to uint16_t. > > RTE_MAX_ETHPORTS is the maximum number of ports, which customized by > the user. To avoid 16-bit unsigned integer overflow, the valid value > of RTE_MAX_ETHPORTS should be set from 0 to UINT16_MAX, and it is > safer to cut one more port from space. > > So we use RTE_BUILD_BUG_ON() to ensure that RTE_MAX_ETHPORTS is less > to UINT16_MAX. > > Fixes: 5b7ba31148a8 ("ethdev: add port ownership") > Cc: stable@dpdk.org > > Signed-off-by: Yunjian Wang Acked-by: Ajit Khaparde > --- > v4: > remove redundant compile checks > v3: > fix code styles suggested by Thomas Monjalon and Andrew Rybchenko > v2: > add RTE_BUILD_BUG_ON() check for RTE_MAX_ETHPORTS validity > --- > lib/librte_ethdev/rte_ethdev.c | 16 +++++++++------- > 1 file changed, 9 insertions(+), 7 deletions(-) > > diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c > index b12bb3854d..0af8e4d76c 100644 > --- a/lib/librte_ethdev/rte_ethdev.c > +++ b/lib/librte_ethdev/rte_ethdev.c > @@ -411,7 +411,9 @@ eth_dev_is_allocated(const struct rte_eth_dev *ethdev) > static struct rte_eth_dev * > eth_dev_allocated(const char *name) > { > - unsigned i; > + uint16_t i; > + > + RTE_BUILD_BUG_ON(RTE_MAX_ETHPORTS >= UINT16_MAX); > > for (i = 0; i < RTE_MAX_ETHPORTS; i++) { > if (rte_eth_devices[i].data != NULL && > @@ -440,7 +442,7 @@ rte_eth_dev_allocated(const char *name) > static uint16_t > eth_dev_find_free_port(void) > { > - unsigned i; > + uint16_t i; > > for (i = 0; i < RTE_MAX_ETHPORTS; i++) { > /* Using shared name field to find a free port. */ > @@ -816,7 +818,7 @@ rte_eth_dev_get_name_by_port(uint16_t port_id, char *name) > int > rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id) > { > - uint32_t pid; > + uint16_t pid; > > if (name == NULL) { > RTE_ETHDEV_LOG(ERR, "Null pointer is specified\n"); > @@ -4290,7 +4292,7 @@ rte_eth_mirror_rule_reset(uint16_t port_id, uint8_t rule_id) > > RTE_INIT(eth_dev_init_cb_lists) > { > - int i; > + uint16_t i; > > for (i = 0; i < RTE_MAX_ETHPORTS; i++) > TAILQ_INIT(&rte_eth_devices[i].link_intr_cbs); > @@ -4303,7 +4305,7 @@ rte_eth_dev_callback_register(uint16_t port_id, > { > struct rte_eth_dev *dev; > struct rte_eth_dev_callback *user_cb; > - uint32_t next_port; /* size is 32-bit to prevent loop wrap-around */ > + uint16_t next_port; > uint16_t last_port; > > if (!cb_fn) > @@ -4366,7 +4368,7 @@ rte_eth_dev_callback_unregister(uint16_t port_id, > int ret; > struct rte_eth_dev *dev; > struct rte_eth_dev_callback *cb, *next; > - uint32_t next_port; /* size is 32-bit to prevent loop wrap-around */ > + uint16_t next_port; > uint16_t last_port; > > if (!cb_fn) > @@ -5507,7 +5509,7 @@ static struct rte_eth_dev_switch { > int > rte_eth_switch_domain_alloc(uint16_t *domain_id) > { > - unsigned int i; > + uint16_t i; > > *domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID; > > -- > 2.18.1 >