From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C274EA0548; Fri, 3 Dec 2021 11:37:15 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 52D0C4014F; Fri, 3 Dec 2021 11:37:14 +0100 (CET) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by mails.dpdk.org (Postfix) with ESMTP id 5A97E40041; Fri, 3 Dec 2021 11:37:13 +0100 (CET) X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: RE: [PATCH v1] gpudev: return EINVAL if invalid input pointer for free and unregister Date: Fri, 3 Dec 2021 11:37:10 +0100 Message-ID: <98CBD80474FA8B44BF855DF32C47DC35D86D35@smartserver.smartshare.dk> In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35D86D34@smartserver.smartshare.dk> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PATCH v1] gpudev: return EINVAL if invalid input pointer for free and unregister Thread-Index: AQHX3G4EdhDcLThKtEqIWzyJTUtRGqwJulSAgADeAwCAAAZHAIAIWNsAgAALPgCACzvMgIAAolgAgABYBICAAAcRYIAACsVQgAFbHLA= References: <20211118192802.23955-1-eagostini@nvidia.com> <20211201213749.GA5097@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> <3625450.hdfAi7Kttb@thomas> <98CBD80474FA8B44BF855DF32C47DC35D86D33@smartserver.smartshare.dk> <98CBD80474FA8B44BF855DF32C47DC35D86D34@smartserver.smartshare.dk> From: =?iso-8859-1?Q?Morten_Br=F8rup?= To: "Ananyev, Konstantin" , "Thomas Monjalon" , "Tyler Retzlaff" , "Richardson, Bruce" Cc: , , "Andrew Rybchenko" , "David Marchand" , "Yigit, Ferruh" X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org > From: Morten Br=F8rup [mailto:mb@smartsharesystems.com] > Sent: Thursday, 2 December 2021 14.56 >=20 > > From: Ananyev, Konstantin [mailto:konstantin.ananyev@intel.com] > > Sent: Thursday, 2 December 2021 14.01 > > > > > > From: Thomas Monjalon [mailto:thomas@monjalon.net] > > > > Sent: Thursday, 2 December 2021 08.19 > > > > > > > > 01/12/2021 22:37, Tyler Retzlaff: > > > > > On Wed, Nov 24, 2021 at 06:04:56PM +0000, Bruce Richardson > wrote: > > > > > > if (ret < 0 && rte_errno =3D=3D EAGAIN) > > > > > > > > > > i only urge that this be explicit as opposed to a range i.e. > ret > > =3D=3D - > > > > 1 > > > > > preferred over ret < 0 > > > > > > > > I don't understand why you think it is important to limit return > > value > > > > to -1. > > > > Why "if (ret =3D=3D -1)" is better than "if (ret < 0)" ? > > > > > > Speaking for myself: > > > > > > For clarity. It leaves no doubt that "it failed" is represented by > > the return value -1, and that the function does not return errno > values > > such as > > > -EINVAL. > > > > > > > But why '< 0' gives you less clarity? > > Negative value means failure - seems perfectly clear to me. >=20 > I disagree: Negative value does not mean failure. Only -1 means > failure. >=20 > There is no -2 return value. There is no -EINVAL return value. >=20 > Testing for (ret < 0) might confuse someone to think that other values > than -1 could be returned as indication of failure, which is not the > case when following the convention where the functions set errno and > return -1 in case of failure. >=20 > It would be different if following a convention where the functions > return -errno in case of failure. In this case, testing (ret < 0) = would > be appropriate. >=20 > So explicitly testing (ret =3D=3D -1) clarifies which of the two > conventions are relevant. >=20 I tested it on Godbolt, and (ret < 0) produces slightly smaller code = than (ret =3D=3D -1) on x86-64: https://godbolt.org/z/3xME3jxq8 A binary test (Error or Data) uses 1 byte less, and a tristate test = (Error, Zero or Data) uses 3 byte less. Although there is no measurable performance difference for a single = instance of this kind of test, we should consider that this kind of test = appears many times in the code, so the saved bytes might add up to = something slightly significant in the instruction cache. My opinion is not so strong anymore... perhaps we should prefer = performance over code readability, also in this case?