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 9024FA0C41; Thu, 18 Nov 2021 03:44:25 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 12C0640687; Thu, 18 Nov 2021 03:44:25 +0100 (CET) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mails.dpdk.org (Postfix) with ESMTP id 7161A40395 for ; Thu, 18 Nov 2021 03:44:23 +0100 (CET) Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Hvkbw56WRz8vQ5; Thu, 18 Nov 2021 10:42:36 +0800 (CST) Received: from kwepemm600004.china.huawei.com (7.193.23.242) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Thu, 18 Nov 2021 10:44:21 +0800 Received: from [10.67.103.231] (10.67.103.231) by kwepemm600004.china.huawei.com (7.193.23.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Thu, 18 Nov 2021 10:44:20 +0800 Message-ID: Date: Thu, 18 Nov 2021 10:44:20 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: [dpdk-dev] [PATCH V1 1/2] examples/ethtool: fix data type of MTU To: David Marchand CC: dev , "Yigit, Ferruh" , "Min Hu (Connor)" References: <1619693609-28244-1-git-send-email-humin29@huawei.com> <1619693609-28244-2-git-send-email-humin29@huawei.com> From: "lihuisong (C)" In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.103.231] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemm600004.china.huawei.com (7.193.23.242) 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 在 2021/11/18 1:49, David Marchand 写道: > On Thu, Apr 29, 2021 at 12:53 PM Min Hu (Connor) wrote: >> From: Huisong Li >> >> This patch changes the data type of 'mtu' in rte_ethtool_net_change_mtu() >> from 'int' to 'uint16_t'. > You did not describe why this change is needed. Ensure that the input parameter of rte_ethtool_net_change_mtu() API in lib/rte_ethtool.c re consistent with rte_eth_dev_set_mtu() in ethdev layer. I will fix commit log. > > >> Fixes: bda68ab9d1e7 ("examples/ethtool: add user-space ethtool sample application") >> Cc: stable@dpdk.org >> >> Signed-off-by: Huisong Li >> --- >> examples/ethtool/ethtool-app/ethapp.c | 6 +----- >> examples/ethtool/lib/rte_ethtool.c | 9 +++++---- >> examples/ethtool/lib/rte_ethtool.h | 2 +- >> 3 files changed, 7 insertions(+), 10 deletions(-) >> >> diff --git a/examples/ethtool/ethtool-app/ethapp.c b/examples/ethtool/ethtool-app/ethapp.c >> index 36a1c37..fc743ce 100644 >> --- a/examples/ethtool/ethtool-app/ethapp.c >> +++ b/examples/ethtool/ethtool-app/ethapp.c >> @@ -521,13 +521,9 @@ pcmd_mtu_callback(void *ptr_params, >> { >> struct pcmd_intstr_params *params = ptr_params; >> int stat; >> - int new_mtu; >> + uint16_t new_mtu; > strtoul can overflow the stack, when storing to new_mtu some lines below. > You should either change new_mtu to unsigned long int or switch > strtoul to some other integer format helper. You are right. I want add an mtu specific cmd parameter structure: struct pcmd_mtu_params {     cmdline_fixed_string_t cmd;     uint16_t port;     uint16_t mtu_value; }; MTU size is limited when users enter the value. Like: cmdline_parse_token_num_t pcmd_mtu_token_port =     TOKEN_NUM_INITIALIZER(struct pcmd_mtu_params, mtu_value, RTE_UINT16); What do you think, David? > >> char *ptr_parse_end; >> >> - if (!rte_eth_dev_is_valid_port(params->port)) { >> - printf("Error: Invalid port number %i\n", params->port); >> - return; >> - } > Adding the check in lib/rte_ethtool.c is ok, but why not keep the > check in the application? All right, let it stay here. > > >> new_mtu = strtoul(params->opt, &ptr_parse_end, 10); >> if (*ptr_parse_end != '\0' || >> new_mtu < RTE_ETHER_MIN_MTU || > With this patch, rte_ethtool_net_change_mtu() now takes a uint16_t. > You should add a check on new_mtu < UINT16_MAX. > If we use above new method, this check can be removed. >> diff --git a/examples/ethtool/lib/rte_ethtool.c b/examples/ethtool/lib/rte_ethtool.c >> index 4132516..73193ed 100644 >> --- a/examples/ethtool/lib/rte_ethtool.c >> +++ b/examples/ethtool/lib/rte_ethtool.c >> @@ -345,12 +345,13 @@ rte_ethtool_net_validate_addr(uint16_t port_id __rte_unused, >> return rte_is_valid_assigned_ether_addr(addr); >> } >> >> + >> int >> -rte_ethtool_net_change_mtu(uint16_t port_id, int mtu) >> +rte_ethtool_net_change_mtu(uint16_t port_id, uint16_t mtu) >> { >> - if (mtu < 0 || mtu > UINT16_MAX) >> - return -EINVAL; >> - return rte_eth_dev_set_mtu(port_id, (uint16_t)mtu); >> + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); >> + >> + return rte_eth_dev_set_mtu(port_id, mtu); >> } >> >> int >> diff --git a/examples/ethtool/lib/rte_ethtool.h b/examples/ethtool/lib/rte_ethtool.h >> index f177096..fe3250e 100644 >> --- a/examples/ethtool/lib/rte_ethtool.h >> +++ b/examples/ethtool/lib/rte_ethtool.h >> @@ -309,7 +309,7 @@ int rte_ethtool_net_validate_addr(uint16_t port_id, >> * - (-EINVAL) if parameters invalid. >> * - others depends on the specific operations implementation. >> */ >> -int rte_ethtool_net_change_mtu(uint16_t port_id, int mtu); >> +int rte_ethtool_net_change_mtu(uint16_t port_id, uint16_t mtu); >> >> /** >> * Retrieve the Ethernet device traffic statistics >> -- >> 2.8.1 >> >