From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id F3DED1B2B0 for ; Thu, 4 Oct 2018 13:46:57 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 8CA0021B10; Thu, 4 Oct 2018 07:46:57 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 04 Oct 2018 07:46:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s=mesmtp; bh=73q3uszGWDPBB9GnLJdSQgAiJDvqb/nELPXn8+Ytrws=; b=IPbHVVUBDsQy jm8RkboNeYVJ+m4TsuhBwG8K9HMPbsbpVL3zfW5CrAW6m21wFputd+dFvWto8htu IJLtjnlYTYMQ4FUWJn9mhzZHIAtR64Na2JUqKlNVgO3YLZnBBYjxn8HN4kq1ww8E p+ugXG1NIGjdQg17/VU33nSgSS3TsgY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=73q3uszGWDPBB9GnLJdSQgAiJDvqb/nELPXn8+Ytr ws=; b=n/GU/pnsW7km3DnEhEJtTxyRkJCDHRIAuz3ShUKBAAGsR/hM6lWnH/quk XGBwI38G+O+UUyBA4BIvqlL/dtZrB9ddXgvOpD94+fD8u42F8LZ5DMuZg9PSbygK Am/OX0GdHSLIndKv/sgw43PXXaaXxgucK2AFCvUD4Got6+hIfUX91ESF4T02i0G9 OF92fmW/xjMOqD4/Q6zRT71kjb/eC/x6UV6IfdVsY1EEnhLKcGBv7ZnVQdNeEnl3 Of/oNJNiLAS+soc/qtcfIztUWhbei/ieC30iv0U5FaHSgqlCpeRU15wZCTT/MVOi +yrPie6r64rBSn7yoXcXOc3IZZsRg== X-ME-Sender: X-ME-Proxy: Received: from xps.localnet (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id 09C7A102EB; Thu, 4 Oct 2018 07:46:55 -0400 (EDT) From: Thomas Monjalon To: =?ISO-8859-1?Q?Ga=EBtan?= Rivet Cc: dev@dpdk.org, ophirmu@mellanox.com, qi.z.zhang@intel.com, ferruh.yigit@intel.com, ktraynor@redhat.com Date: Thu, 04 Oct 2018 13:46:54 +0200 Message-ID: <3504838.42QrpyPWfC@xps> In-Reply-To: <20181004094437.yx4tfebyxbsfp6ry@bidouze.vm.6wind.com> References: <20180907222727.20521-1-thomas@monjalon.net> <20181003231046.26772-6-thomas@monjalon.net> <20181004094437.yx4tfebyxbsfp6ry@bidouze.vm.6wind.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" 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:46:58 -0000 04/10/2018 11:44, Ga=EBtan 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) > > =20 > > 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 =3D NULL; > > + int size, length =3D -1; > > =20 > > - bus =3D rte_bus_find_by_name(busname); > > - if (bus =3D=3D NULL) { > > - RTE_LOG(ERR, EAL, "Cannot find bus (%s)\n", busname); > > - return -ENOENT; > > - } > > + do { /* 2 iterations: first is to know string length */ > > + size =3D length + 1; > > + length =3D snprintf(devargs, size, "%s:%s,%s", busname, devname, drv= args); > > + if (length >=3D size) > > + devargs =3D malloc(length + 1); > > + if (devargs =3D=3D NULL) > > + return -ENOMEM; > > + } while (size =3D=3D 0); >=20 > 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. >=20 > You should remove this loop, which then allow removing size, and forces u= sing > 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 =3D snprintf(devargs, 0, "%s:%s,%s", busname, devname, drvargs); if (length < 0) return -EINVAL; devargs =3D malloc(length + 1); if (devargs =3D=3D NULL) return -ENOMEM; snprintf(devargs, length + 1, "%s:%s,%s", busname, devname, drvargs); Any preference?