From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by dpdk.org (Postfix) with ESMTP id A6B012C38 for ; Fri, 1 Mar 2019 19:42:24 +0100 (CET) Received: by mail-pf1-f194.google.com with SMTP id i19so11826558pfd.0 for ; Fri, 01 Mar 2019 10:42:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rv0Zn8mhoYp5Joa5Cf2UDIAYOu+4yPA+jRloyCe1UjU=; b=YP707jXqQh3Fn3mUIa3zGcGe2b2hyk0ABy1A1MK7HXxAf9FNwaihcPmpXUh4CQ4Qs0 FaEw9SITYhqY2o5I1rTrkm7FWW02vG7w1MhlPqt2EeShcvOvnIeA8Qf2uHS10UmQmvaB YxXpxhy5ruuEP6g8Vt/5nX4RdmClInK1HoUOqRWwB9fVF1m4mfiBTKuGXBPQP9Gk8HPj k5bp4pbcu/CIoePoksgXfTXC0rPjA9XnS671g579M8RcDflMiPn0qBKtYAghyHqX66Rp cAGgGv99nUaAdxdNLVtdHwRFSHMjSByoQKh6/oS5vR02V8bXYJsH1D9SnaaW8EJMHjai Z65w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rv0Zn8mhoYp5Joa5Cf2UDIAYOu+4yPA+jRloyCe1UjU=; b=afOjp6XWhYDG0M1Lx3mxPaqsL4xl69BqSJQYYPmbv/helYlM/VNggFHoOHhw3AYS8r zHy4+OdmUOSdUFkX3s1diMcNWoSfoXzKNIKqY3SgkkvDK7T8dU+FBxb5T8pIqz7P9JCs 4PeSKmZhalMhY4dH/RNgIr+OYQR/fSneUM4LQMj8s1iJ+o2I3hPSYkcEgggtrKJ/gJoK ucZlOqjJ7B6xzfRxgbc0dt8oJM0DlFouEs2lIQ+IgXyRckPKy6K75xzF++1FJHaIkA4u JdDp1bEjw9+o2ITW/zuuOwrRAXN5pOVIZZuOS4ZSmenZL9HBTGGiSfKfcoTA5TZaW48f CJtw== X-Gm-Message-State: AHQUAubcb7XeNvB6J0/59bj72ASxbTskUJUhnWMMiiNQxIw7K3MzKril tvKmW8unkoD5DNQfua0MwVz5HQ== X-Google-Smtp-Source: AHgI3IYJrgzbbm5/5jLuHUrLvNQqs8Y6XqCKak2BLMwyK6jpkWaV8aSrGuNdoeKlDSjFBL5pRf9Dwg== X-Received: by 2002:a62:b608:: with SMTP id j8mr7134241pff.183.1551465743822; Fri, 01 Mar 2019 10:42:23 -0800 (PST) Received: from shemminger-XPS-13-9360 (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id b6sm21850059pgl.49.2019.03.01.10.42.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2019 10:42:23 -0800 (PST) Date: Fri, 1 Mar 2019 10:42:21 -0800 From: Stephen Hemminger To: Andrew Rybchenko Cc: , Ferruh Yigit , Thomas Monjalon Message-ID: <20190301104221.0d767d69@shemminger-XPS-13-9360> In-Reply-To: <8f248bd3-1ae6-c8a1-ee6e-37742bd6ea90@solarflare.com> References: <20190228224754.26511-1-stephen@networkplumber.org> <20190228224754.26511-3-stephen@networkplumber.org> <8f248bd3-1ae6-c8a1-ee6e-37742bd6ea90@solarflare.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH 2/2] ethdev: use strlcpy instead of snprintf on initialization X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Mar 2019 18:42:25 -0000 On Fri, 1 Mar 2019 10:48:58 +0300 Andrew Rybchenko wrote: > On 3/1/19 1:47 AM, Stephen Hemminger wrote: > > Don't need to use snprintf for simple name copy. > > > > Signed-off-by: Stephen Hemminger > > --- > > lib/librte_ethdev/rte_ethdev.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c > > index 95889ed206db..8bd54dcf58c1 100644 > > --- a/lib/librte_ethdev/rte_ethdev.c > > +++ b/lib/librte_ethdev/rte_ethdev.c > > @@ -459,7 +459,7 @@ rte_eth_dev_allocate(const char *name) > > } > > > > eth_dev = eth_dev_get(port_id); > > - snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name); > > + strlcpy(eth_dev->data->name, name, RTE_ETH_NAME_MAX_LEN); > > Why is sizeof() substituted with RTE_ETH_NAME_MAX_LEN? Same thing, I just wanted to make the length obvious to the reader. > I thought that sizeof() is the first choice in such cases since it is a > bit more > safer vs possible changes in the code. > > BTW, wouldn't it be more friendly to check name length on entry and > reject if it is too long? (and same for rte_eth_dev_create()) It is impossible for name to long since since both structures are the same. > I agree that strlcpy() should be used anyway. > > > eth_dev->data->port_id = port_id; > > eth_dev->data->mtu = ETHER_MTU; > > >