[dpdk-dev] [PATCH] ethdev: check for invalid device name

Zhang, Qi Z qi.z.zhang at intel.com
Thu Mar 14 02:01:45 CET 2019



> -----Original Message-----
> From: Stephen Hemminger [mailto:stephen at networkplumber.org]
> Sent: Thursday, March 14, 2019 1:33 AM
> To: Zhang, Qi Z <qi.z.zhang at intel.com>
> Cc: dev at dpdk.org
> Subject: Re: [dpdk-dev] [PATCH] ethdev: check for invalid device name
> 
> On Wed, 13 Mar 2019 12:52:50 +0000
> "Zhang, Qi Z" <qi.z.zhang at intel.com> wrote:
> 
> > HI
> >
> > > -----Original Message-----
> > > From: dev [mailto:dev-bounces at dpdk.org] On Behalf Of Stephen
> > > Hemminger
> > > Sent: Tuesday, March 12, 2019 2:16 AM
> > > To: dev at dpdk.org
> > > Cc: Stephen Hemminger <stephen at networkplumber.org>
> > > Subject: [dpdk-dev] [PATCH] ethdev: check for invalid device name
> > >
> > > Do not allow creating a ethernet device with a name over the allowed
> > > maximum (or zero length). This is safer than silently truncating which is what
> happens now.
> > >
> > > Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
> > > Acked-by: Andrew Rybchenko <arybchenko at solarflare.com>
> > > ---
> > > v1 - previously sent as RFC
> > >
> > >  lib/librte_ethdev/rte_ethdev.c | 10 ++++++++++
> > >  1 file changed, 10 insertions(+)
> > >
> > > diff --git a/lib/librte_ethdev/rte_ethdev.c
> > > b/lib/librte_ethdev/rte_ethdev.c index 85c1794968dd..0b81980ff71c
> > > 100644
> > > --- a/lib/librte_ethdev/rte_ethdev.c
> > > +++ b/lib/librte_ethdev/rte_ethdev.c
> > > @@ -439,6 +439,16 @@ rte_eth_dev_allocate(const char *name)
> > >  	uint16_t port_id;
> > >  	struct rte_eth_dev *eth_dev = NULL;
> > >
> > > +	if (*name) {
> >
> > Is above check same as "strlen(name) == 0"?
> 
> Yes, but checking for first null byte is slightly quicker. Alternative would be to call
> strnlen() once.

But you are checking the not null byte here right? should it be if (!(*name))?
	


More information about the dev mailing list