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 09FF8A0C41; Wed, 17 Nov 2021 18:49:53 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CBED241141; Wed, 17 Nov 2021 18:49:53 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id C8E9241141 for ; Wed, 17 Nov 2021 18:49:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637171392; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=yDebTiHO8GKDKHGTjoAQsva73RkDnG9fTR/2pb+HIYM=; b=gNXlj96HBZQzdv3cFFcml5b4+Rn3KAvCPnv0tLhVyXc+GtNhsS0+ULdWfECP5/1GVpXVLo //ECdp6zJ1JiiX/45DgHM8J6JJu/Pg6Cmb8BltTjt2i+jZIR2Xk8mwijXvLADyvZAv2h5A ObLcZbPi9sC/7KxEj6FBBU6d/bkcWns= Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-100-_14963WlOtue6mJVRg2mVQ-1; Wed, 17 Nov 2021 12:49:51 -0500 X-MC-Unique: _14963WlOtue6mJVRg2mVQ-1 Received: by mail-lf1-f72.google.com with SMTP id u20-20020a056512129400b0040373ffc60bso2045757lfs.15 for ; Wed, 17 Nov 2021 09:49:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=yDebTiHO8GKDKHGTjoAQsva73RkDnG9fTR/2pb+HIYM=; b=HodcAEjk1yrIUvJ9F6Q+qQiqcrTdn4BFr86kS56tIvMzTBfJqHhOHdrgN9rrQErIxp 3KQ4UaQM4/KWtxTH/UYSzO1OiUkBBKKXv0KbDz9mGEHkfpYMhZxNhYbuVoODBjCe39Cb UcfeKuoHyUSGea5aJd65V+jyDBGygjn6IGL6CbUAp8fh8yC3I4t6IUJlCJ1EavlCvt00 PVTnl8JeD2VjHBlWIRtQR3XEeN3+DY/mYGKfwbkF4h1UV0j1M89pQmGXdXlLKr7AbbcI Xr2Yd+PIPbips4fOL850Plg0EQpUyJ0q44vr0OmaU98O9W/77YwaPjueu5HabPgatCr7 7ldA== X-Gm-Message-State: AOAM533/NjJ9WVXl97BCYfF+QlyTX6PoVR4P24A471PnmWYTlWqZI5gG 4bVhp7MKJdDqRRPlfi4bAd9Z1A9t0iVSdtYhqi2KNXitGFj+Mjq+OSto3hserzNPfVqtpxP6x0Y SBSwpb+Fa8mKBCDUetec= X-Received: by 2002:ac2:42c6:: with SMTP id n6mr16556173lfl.553.1637171389453; Wed, 17 Nov 2021 09:49:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJxbid/hfQE4Vv+VOhzgMA+KnbEXxMfewrsHxoqrWAt54qp7maIUXdedEll2YocKLClhc23fGDATk1UmsfET+dY= X-Received: by 2002:ac2:42c6:: with SMTP id n6mr16556131lfl.553.1637171389064; Wed, 17 Nov 2021 09:49:49 -0800 (PST) MIME-Version: 1.0 References: <1619693609-28244-1-git-send-email-humin29@huawei.com> <1619693609-28244-2-git-send-email-humin29@huawei.com> In-Reply-To: <1619693609-28244-2-git-send-email-humin29@huawei.com> From: David Marchand Date: Wed, 17 Nov 2021 18:49:38 +0100 Message-ID: Subject: Re: [dpdk-dev] [PATCH V1 1/2] examples/ethtool: fix data type of MTU To: "Min Hu (Connor)" Cc: dev , "Yigit, Ferruh" Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dmarchan@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" 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 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. > > 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. > 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? > 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. > 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 > -- David Marchand