From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by dpdk.org (Postfix) with ESMTP id 74A451B273 for ; Thu, 4 Oct 2018 13:51:50 +0200 (CEST) Received: by mail-wm1-f68.google.com with SMTP id e187-v6so1224273wmf.0 for ; Thu, 04 Oct 2018 04:51:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=HR5bJrysY6nmpiHZaDM0bNyI2inFBKFcLKTvcguIoZk=; b=F9lqYseGglO5Mf1KzWFFku5bCXZp+k7DHZq1GPnruqE6t8Kk9NThP/McqeJ1df/HEH sB6P91h0ofJ/pSyt9jo5huErAhko5Uhw5QW0m2vZEEexCdWLt1k8rYL3EJCoiKDqmwgz g6pGpAL3XyRDPED19gFyLZuMLE7XileHf0PImuTJeBWL2uNAI6WixEEJgcC3GgYZhYor yWoZjsTIvBpWWlAsSLXrWTX2azeZn6aXv6IdZm2Tx5+Nw/fqdlaWixxItUr+geg+KvCb IuLj0BLkg50/QQH4bOdPurFmPCcwrE1Lpu8uiyMx696KHbGedkmbWLUDRS8cz8x6VJ4f wUtQ== 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:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=HR5bJrysY6nmpiHZaDM0bNyI2inFBKFcLKTvcguIoZk=; b=ndrq8vKF9h6HIimMtvRKtqkOHl4d26Pk7KgnNe/sBcS2JH/WVT4AcO0GqolNG/w9aD gZXG4uK0nF80fl+Ru6uJXCBpsBS/Qn0caOK04NesbArSHPV7DYTk2IzNvgtgBXxA1AwI bOkESlwPQSiJQwmyk/sxwy7JPlkWALffx5SANZUBqt9bGT52vtLZyLPGrXUj5vEA0pyr SzcJqfyXW25N9j4PV96IdhAe4gch89sb4oNXJHQiEEEVUaeCphkT7hR9dvHSBJPjgS+8 CbvdQm9Cec9xu7UNMMRTSqu/P+HspAE7L5SlLEZdNKawi2vnJmuM3fvgv+nxlkfuM23Z yEWA== X-Gm-Message-State: ABuFfojugTxbE+TOsAVpWAgkDc+dTWQR1HTbAVDchy8TA15kHjYtQdrA gSNax6i7e6uBGAx7dxY6p2LXnQ== X-Google-Smtp-Source: ACcGV63En6+D5ez4mwDeGd7tsbChcH1EjI9zU87mU9ABifZvxO+aAJFepZtsviLaVVi2CqWBG00A7w== X-Received: by 2002:a1c:118c:: with SMTP id 134-v6mr4326372wmr.75.1538653909824; Thu, 04 Oct 2018 04:51:49 -0700 (PDT) Received: from bidouze.vm.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id e142-v6sm11297965wmf.20.2018.10.04.04.51.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Oct 2018 04:51:49 -0700 (PDT) Date: Thu, 4 Oct 2018 13:51:31 +0200 From: =?iso-8859-1?Q?Ga=EBtan?= Rivet To: Thomas Monjalon Cc: dev@dpdk.org, ophirmu@mellanox.com, qi.z.zhang@intel.com, ferruh.yigit@intel.com, ktraynor@redhat.com Message-ID: <20181004115131.do3mrikxujq7dx4o@bidouze.vm.6wind.com> References: <20180907222727.20521-1-thomas@monjalon.net> <20181003231046.26772-6-thomas@monjalon.net> <20181004094437.yx4tfebyxbsfp6ry@bidouze.vm.6wind.com> <3504838.42QrpyPWfC@xps> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3504838.42QrpyPWfC@xps> User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [dpdk-dev] [PATCH v5 5/5] eal: simplify parameters of hotplug functions 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: Thu, 04 Oct 2018 11:51:50 -0000 On Thu, Oct 04, 2018 at 01:46:54PM +0200, Thomas Monjalon wrote: > 04/10/2018 11:44, Gaëtan Rivet: > > On Thu, Oct 04, 2018 at 01:10:46AM +0200, Thomas Monjalon wrote: > > > --- a/lib/librte_eal/common/eal_common_dev.c > > > +++ b/lib/librte_eal/common/eal_common_dev.c > > > @@ -129,46 +129,61 @@ 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) > > > { > > > - struct rte_bus *bus; > > > - struct rte_device *dev; > > > - struct rte_devargs *da; > > > int ret; > > > + char *devargs = NULL; > > > + int size, length = -1; > > > > > > - bus = rte_bus_find_by_name(busname); > > > - if (bus == NULL) { > > > - RTE_LOG(ERR, EAL, "Cannot find bus (%s)\n", busname); > > > - return -ENOENT; > > > - } > > > + 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); > > > > I don't see a good reason for writing it this way. > > You use an additional state (size) and complicate something that is > > pretty straightforward. To make sure no error was written here, I had to > > do step-by-step careful reading, this should not be required by clean > > code. > > > > You should remove this loop, which then allow removing size, and forces using > > simple code-flow. > > The only reason for this loop is to avoid duplicating the snprintf format > in two calls. > > It could be replaced by this: > > length = snprintf(devargs, 0, "%s:%s,%s", busname, devname, drvargs); > if (length < 0) > return -EINVAL; > devargs = malloc(length + 1); > if (devargs == NULL) > return -ENOMEM; > snprintf(devargs, length + 1, "%s:%s,%s", busname, devname, drvargs); > > Any preference? > > Yes, the second is cleaner IMO. -- Gaëtan Rivet 6WIND