From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Monjalon Subject: Re: [PATCH v3 4/4] eal: simplify parameters of hotplug functions Date: Mon, 01 Oct 2018 22:03:59 +0200 Message-ID: <5671799.PGEWDzNARk@xps> References: <20180907222727.20521-1-thomas@monjalon.net> <20180928162144.1972-5-thomas@monjalon.net> <7955fa9c-21ea-295b-2c1c-5a0ab7a472c6@solarflare.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7Bit Cc: dev@dpdk.org, gaetan.rivet@6wind.com, ophirmu@mellanox.com, qi.z.zhang@intel.com, ferruh.yigit@intel.com, ktraynor@redhat.com To: Andrew Rybchenko Return-path: Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id 1FC8E58EC for ; Mon, 1 Oct 2018 22:04:03 +0200 (CEST) In-Reply-To: <7955fa9c-21ea-295b-2c1c-5a0ab7a472c6@solarflare.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 01/10/2018 13:26, Andrew Rybchenko: > On 9/28/18 7:21 PM, Thomas Monjalon wrote: > > All information about a device to probe can be grouped > > in a common string, which is what we usually call devargs. > > An application should not have to parse this string before > > calling the EAL probe function. > > And the syntax could evolve to be more complex and support > > matching multiple devices in one string. > > That's why the bus name and device name should be removed from > > rte_eal_hotplug_add(). > > Instead of changing this function, a simpler one is added > > and used in the old one, which may be deprecated later. > > > > When removing a device, we already know its rte_device handle > > which can be directly passed as parameter of rte_eal_hotplug_remove(). > > If the rte_device is not known, it can be retrieved with the devargs, > > by iterating in the device list (future RTE_DEV_FOREACH()). > > Similarly to the probing case, a new function is added > > and used in the old one, which may be deprecated later. > > The new function is used in failsafe, because the replacement is easy. > > > > Signed-off-by: Thomas Monjalon > > Minor memory leak below, when fixed: > > Reviewed-by: Andrew Rybchenko > > <...> > > > diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c > > index a9be58edf..b40e4c0d0 100644 > > --- a/lib/librte_eal/common/eal_common_dev.c > > +++ b/lib/librte_eal/common/eal_common_dev.c > > @@ -129,46 +129,57 @@ int rte_eal_dev_detach(struct rte_device *dev) > > > > int > > rte_eal_hotplug_add(const char *busname, const char *devname, > > - const char *devargs) > > + const char *drvargs) > > +{ > > + char *devargs = NULL; > > + int size, length = -1; > > + > > + do { /* 2 iterations: first is to know string length */ > > + size = length + 1; > > + length = snprintf(devargs, size, "%s:%s,%s", busname, devname, drvargs); > > + if (length >= size) > > + devargs = malloc(length + 1); > > + if (devargs == NULL) > > + return -ENOMEM; > > + } while (size == 0); > > + > > + return rte_dev_probe(devargs); > > I think we should free devargs after the call. Good catch! Will fix in v4, thank you.