From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id C58DBA04B6; Tue, 13 Oct 2020 10:55:37 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A42361DABC; Tue, 13 Oct 2020 10:55:36 +0200 (CEST) Received: from new3-smtp.messagingengine.com (new3-smtp.messagingengine.com [66.111.4.229]) by dpdk.org (Postfix) with ESMTP id 4118F1DAB5 for ; Tue, 13 Oct 2020 10:55:34 +0200 (CEST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailnew.nyi.internal (Postfix) with ESMTP id 85F135802DF; Tue, 13 Oct 2020 04:55:33 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Tue, 13 Oct 2020 04:55:33 -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=fm2; bh= a1h0+wQepV2nxdNw4HVQW+QimHUbQFTj6B567mdrYQA=; b=uT8LrGC60SOXIR20 yNgkkK6qblyj4WyiNS+RI+C3Poa8OUpl8QYGRf5RVYRx9bG0G7w+EqWM25HRjJEO gOoesHheDd/KnYSy+GWGPYNYrT3WfI+aLfpbFkgD/Pv1czAXcKcWFdwXX1ZR0DvM Qxo7ItqzmMg3JUK6Vcw9Wmh2UWZ1/ARaybrB7rGd1LNBWR7PGlTRal3niBub06dG VtHxf1ESWzJ1bGQXgh1ZR66RD2wJSfLzSANW0VT6vfcqT1SL6IeDcHl4v0aHAsPM uEo+HLJqD2RoUvwygI4Vf5nXteHlbk0lHtKu6ncE58EjrzzQ4lEWtPnHtw3Jf641 /JuCJA== 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=fm1; bh=a1h0+wQepV2nxdNw4HVQW+QimHUbQFTj6B567mdrY QA=; b=E9TKnHoUZPmn056pMlIkeWSBJ5lA5UK95GKFcaIGCRc8fX2fISxmqa8Of 9/X8Sr6B2t1wXGVKrjHCaXwgz+c0cHYb6K4wZonoXWle1CfI+rOPsw7QR8gaqZSd wcVy+Csi59lqCAgeo23/IqXUfTIJW/cQSHDrJ1dvj7LZEwWvXa9yECDRtYAFZn/L CpDx0XGTGEqjN/vua40EDSIx/RwlfZ7ioDIOrsg8q/Ir+XCAJGZVQSMaSXKSuXJn GMHluEA6SCIZf9di7SJj8hpn7pRGGtp/73ObnqwEjZvZmF/rDJzlTHVD5DNZustF 9Qxeb/YP1HlcdatA9ZdGBISgBX7hg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrheelgddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkjghfggfgtgesthfuredttddtvdenucfhrhhomhepvfhhohhmrghs ucfoohhnjhgrlhhonhcuoehthhhomhgrshesmhhonhhjrghlohhnrdhnvghtqeenucggtf frrghtthgvrhhnpedugefgvdefudfftdefgeelgffhueekgfffhfeujedtteeutdejueei iedvffegheenucfkphepjeejrddufeegrddvtdefrddukeegnecuvehluhhsthgvrhfuih iivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepthhhohhmrghssehmohhnjhgrlhho nhdrnhgvth 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 6A1803064680; Tue, 13 Oct 2020 04:55:29 -0400 (EDT) From: Thomas Monjalon To: Andrew Rybchenko Cc: Ferruh Yigit , dev@dpdk.org, arybchenko@solarflare.com, Liron Himi , Stephen Hemminger , Ray Kinsella , Neil Horman , Rahul Lakkireddy , Gaetan Rivet , Jakub Grajciar , Matan Azrad , Shahaf Shuler , Viacheslav Ovsiienko , Zyta Szpak , Stephen Hemminger , "K. Y. Srinivasan" , Haiyang Zhang , Long Li , Maxime Coquelin , Chenbo Xia , Zhihong Wang Date: Tue, 13 Oct 2020 10:55:28 +0200 Message-ID: <13936658.LjDx0tDdet@thomas> In-Reply-To: References: <20200913220711.3768597-1-thomas@monjalon.net> <1850948.foQ0BKb2Qe@thomas> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Subject: Re: [dpdk-dev] [PATCH v4 3/3] ethdev: allow close function to return an error 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 13/10/2020 10:40, Andrew Rybchenko: > On 10/6/20 1:57 PM, Thomas Monjalon wrote: > > 06/10/2020 11:43, Ferruh Yigit: > >> On 10/5/2020 6:08 PM, Thomas Monjalon wrote: > >>> The API function rte_eth_dev_close() was returning void. > >>> The return type is changed to int for notifying of errors. > >>> > >>> If an error happens during a close operation, > >>> the status of the port is undefined, > >>> a maximum of resources having been freed. > >>> > >>> Signed-off-by: Thomas Monjalon > >>> Reviewed-by: Liron Himi > >>> Acked-by: Stephen Hemminger > >> > >> <...> > >> > >>> -void > >>> +int > >>> rte_eth_dev_close(uint16_t port_id) > >>> { > >>> struct rte_eth_dev *dev; > >>> + int firsterr, binerr; > >>> + int *lasterr = &firsterr; > >>> > >>> - RTE_ETH_VALID_PORTID_OR_RET(port_id); > >>> + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); > > Shouldn't it be -ENODEV in fact? Yes you're right. > IMHO it would be nice to make it uniform across ethdev API. Yes, do you want to make the patch to change other occurences to ENODEV? > >>> dev = &rte_eth_devices[port_id]; > >>> > >>> - RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close); > >>> - (*dev->dev_ops->dev_close)(dev); > >>> + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_close, -ENOTSUP); > >>> + *lasterr = (*dev->dev_ops->dev_close)(dev); > >>> + if (*lasterr != 0) > >>> + lasterr = &binerr; > >>> > >>> rte_ethdev_trace_close(port_id); > >>> - rte_eth_dev_release_port(dev); > >>> + *lasterr = rte_eth_dev_release_port(dev); > >>> + > >>> + return firsterr; > >>> } > >> > >> This may be personal taste but above error handling looks like unnecessary > >> complex, what do you think something like below: > >> > >> close_err = (*dev->dev_ops->dev_close)(dev); > >> release_err = rte_eth_dev_release_port(dev); > >> return close_err ? close_err : release_err; > > > > This is what I did first. Then thought about this "elegant" handling. > > The pointer solution is just one more line and is more future proof. > > > > I'm fine with any choice. Andrew? > > > > Hm, really hard to make a choice. I tend to choose Thomas's > version. Yes, I agree that it is a bit over-complicated in > this particular case, but thoughts to be future-proof > overweight for me. Plus it adds a pattern on how to handle > such cases in the future. Yes it's an elegant pattern :)