From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 9F1B8A0547;
	Thu, 29 Apr 2021 12:53:33 +0200 (CEST)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 7C2A441315;
	Thu, 29 Apr 2021 12:53:30 +0200 (CEST)
Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32])
 by mails.dpdk.org (Postfix) with ESMTP id CCFBF412C6
 for <dev@dpdk.org>; Thu, 29 Apr 2021 12:53:27 +0200 (CEST)
Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58])
 by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4FWC3c09x4zjcJf
 for <dev@dpdk.org>; Thu, 29 Apr 2021 18:51:24 +0800 (CST)
Received: from localhost.localdomain (10.69.192.56) by
 DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id
 14.3.498.0; Thu, 29 Apr 2021 18:53:21 +0800
From: "Min Hu (Connor)" <humin29@huawei.com>
To: <dev@dpdk.org>
CC: <ferruh.yigit@intel.com>
Date: Thu, 29 Apr 2021 18:53:28 +0800
Message-ID: <1619693609-28244-2-git-send-email-humin29@huawei.com>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <1619693609-28244-1-git-send-email-humin29@huawei.com>
References: <1619693609-28244-1-git-send-email-humin29@huawei.com>
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [10.69.192.56]
X-CFilter-Loop: Reflected
Subject: [dpdk-dev] [PATCH V1 1/2] examples/ethtool: fix data type of MTU
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>

From: Huisong Li <lihuisong@huawei.com>

This patch changes the data type of 'mtu' in rte_ethtool_net_change_mtu()
from 'int' to 'uint16_t'.

Fixes: bda68ab9d1e7 ("examples/ethtool: add user-space ethtool sample application")
Cc: stable@dpdk.org

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 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;
 	char *ptr_parse_end;
 
-	if (!rte_eth_dev_is_valid_port(params->port)) {
-		printf("Error: Invalid port number %i\n", params->port);
-		return;
-	}
 	new_mtu = strtoul(params->opt, &ptr_parse_end, 10);
 	if (*ptr_parse_end != '\0' ||
 			new_mtu < RTE_ETHER_MIN_MTU ||
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