Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5790770pxb; Thu, 20 Jan 2022 04:47:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJwclB6JyIOGubwZb2n/8SL3sE0txOlSQwcYqx8rsqEdym4Az+l27FDJSnukDhgwyDYRG6J3 X-Received: by 2002:a63:5712:: with SMTP id l18mr15661043pgb.343.1642682847099; Thu, 20 Jan 2022 04:47:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642682847; cv=none; d=google.com; s=arc-20160816; b=HkHPmKHCDbgg80t9iJF3iOCoL8qw6PgOHSZaeqP6+ZirExbLCMpK8tRKk+X/ZqQxcq bqkJm4D4Dd0oSYcNAgwZddlmmq7Gx+I3F9M0ymr/uiAQGTuGRV9S5LpyifC4Gs7YviGD NZlvNi81ZKvjbsSvLHe+wqB8Co+VRPW7R2kjB21mS0Kgxdq96vJEelms1G3wl2jkrsAf i3RrLEpN/cD5mb+0XHSVspZK1FEEaDQcrVmKdn0U5nZ+E/FmyYm7aGMCmgyIngvyTJ5P T9kQDbKRNQTUexxuRUCMvUBi4qffOm5W/Nv8DcFINejiqOkE2b5j82/IBaq2F5znWCnn /exQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=dheyvG3n0eTBoJkLXD+hO8rfmhug9aGrlr2gF6H1v4w=; b=Wx3BytiPCptNMiLhzzV0vEyq5YJHQnymx+2MnwKZjeYuMgMpCxb4dixsDhAINaMYHh /RDjX3Ouzst9Qp/W3Yb/Dj2oZqqlQ2guE6eKdNU8l8oYe0tC/Zc+rSAzBalVjO3cH+Dy ElqZHuJesFf9sPcL1fd23ruZjM3p3bfYdhHq9sFJ4tW1+d/PNQ1KiExDCHlmoWZU4DRC aupumzW4ZaCqK2ZVbyZHrOByRheZAUTi7fGFYG04vfHtl0SfLepQFETi9QKamRhJaqFJ rfR1Rhb9z0dxj6XQXS64Th/zEbLRuuXYvPSjUVOyIitqqlmMTeV5SAB0goCPMVT9rJ6W vdcg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t19si1315270pgu.571.2022.01.20.04.47.14; Thu, 20 Jan 2022 04:47:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238857AbiARObJ (ORCPT + 99 others); Tue, 18 Jan 2022 09:31:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238947AbiARObH (ORCPT ); Tue, 18 Jan 2022 09:31:07 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87BF1C061574 for ; Tue, 18 Jan 2022 06:31:07 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n9pUj-0000wL-Of; Tue, 18 Jan 2022 15:29:57 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n9pUY-00B1DJ-N0; Tue, 18 Jan 2022 15:29:45 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1n9pUX-0003HD-OO; Tue, 18 Jan 2022 15:29:45 +0100 Date: Tue, 18 Jan 2022 15:29:45 +0100 From: Uwe =?utf-8?Q?Kleine-K=C3=B6nig?= To: Geert Uytterhoeven Cc: Andrew Lunn , Ulf Hansson , Vignesh Raghavendra , KVM list , "Rafael J. Wysocki" , linux-iio@vger.kernel.org, Linus Walleij , Amit Kucheria , ALSA Development Mailing List , Jaroslav Kysela , Guenter Roeck , Thierry Reding , MTD Maling List , Linux I2C , Miquel Raynal , linux-phy@lists.infradead.org, linux-spi , Jiri Slaby , "David S. Miller" , Khuong Dinh , Florian Fainelli , Matthias Schiffer , Kamal Dasu , Greg Kroah-Hartman , Lee Jones , Bartosz Golaszewski , Daniel Lezcano , Kishon Vijay Abraham I , bcm-kernel-feedback-list , "open list:SERIAL DRIVERS" , Jakub Kicinski , Zhang Rui , platform-driver-x86@vger.kernel.org, Linux PWM List , Robert Richter , Saravanan Sekar , Corey Minyard , Linux PM list , Liam Girdwood , Mauro Carvalho Chehab , John Garry , Peter Korsgaard , William Breathitt Gray , Mark Gross , Hans de Goede , Alex Williamson , Mark Brown , Borislav Petkov , Takashi Iwai , Matthias Brugger , openipmi-developer@lists.sourceforge.net, Andy Shevchenko , Benson Leung , Pengutronix Kernel Team , Linux ARM , linux-edac@vger.kernel.org, Tony Luck , Richard Weinberger , Mun Yew Tham , Eric Auger , netdev , "open list:GPIO SUBSYSTEM" , Cornelia Huck , Linux MMC List , Joakim Zhang , Linux Kernel Mailing List , Linux-Renesas , Sergey Shtylyov , Vinod Koul , James Morse , Zha Qipeng , Sebastian Reichel , Niklas =?utf-8?Q?S=C3=B6derlund?= , linux-mediatek@lists.infradead.org, Brian Norris , Yoshihiro Shimoda Subject: Re: [PATCH 1/2] platform: make platform_get_irq_optional() optional Message-ID: <20220118142945.6y3rmvzt44pjpr4z@pengutronix.de> References: <20220117092444.opoedfcf5k5u6otq@pengutronix.de> <20220117114923.d5vajgitxneec7j7@pengutronix.de> <20220117170609.yxaamvqdkivs56ju@pengutronix.de> <20220118090913.pjumkq4zf4iqtlha@pengutronix.de> <20220118120806.pbjsat4ulg3vnhsh@pengutronix.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="daitmup5biyyqkwr" Content-Disposition: inline In-Reply-To: X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --daitmup5biyyqkwr Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jan 18, 2022 at 01:49:15PM +0100, Geert Uytterhoeven wrote: > nst the magic not-found value (so no implementation detail magic > > > > leaks into the caller code) and just pass it to the next API functi= on=3D > . > > > > (And my expectation would be that if you chose to represent not-fou= nd=3D > by > > > > (void *)66 instead of NULL, you won't have to adapt any user, just = th=3D > e > > > > framework internal checks. This is a good thing!) > > > > > > Ah, there is the wrong assumption: drivers sometimes do need to know > > > if the resource was found, and thus do need to know about (void *)66, > > > -ENODEV, or -ENXIO. I already gave examples for IRQ and clk before. > > > I can imagine these exist for gpiod and regulator, too, as soon as > > > you go beyond the trivial "enable" and "disable" use-cases. > > > > My premise is that every user who has to check for "not found" > > explicitly should not use (clk|gpiod)_get_optional() but > > (clk|gpiod)_get() and do proper (and explicit) error handling for > > -ENODEV. (clk|gpiod)_get_optional() is only for these trivial use-cases. > > > > > And 0/NULL vs. > 0 is the natural check here: missing, but not > > > an error. > > > > For me it it 100% irrelevant if "not found" is an error for the query > > function or not. I just have to be able to check for "not found" and > > react accordingly. > > > > And adding a function > > > > def platform_get_irq_opional(): > > ret =3D3D platform_get_irq() > > if ret =3D3D=3D3D -ENXIO: > > return 0 > > return ret > > > > it's not a useful addition to the API if I cannot use 0 as a dummy > > because it doesn't simplify the caller enough to justify the additional > > function. > > > > The only thing I need to be able is to distinguish the cases "there is > > an irq", "there is no irq" and anything else is "there is a problem I > > cannot handle and so forward it to my caller". The semantic of > > platform_get_irq() is able to satisfy this requirement[1], so why intro= du=3D > ce > > platform_get_irq_opional() for the small advantage that I can check for > > not-found using > > > > if (!irq) > > > > instead of > > > > if (irq !=3D3D -ENXIO) > > > > ? The semantic of platform_get_irq() is easier ("Either a usable > > non-negative irq number or a negative error number") compared to > > platform_get_irq_optional() ("Either a usable positive irq number or a > > negative error number or 0 meaning not found"). Usage of > > platform_get_irq() isn't harder or more expensive (neither for a human > > reader nor for a maching running the resulting compiled code). > > For a human reader > > > > if (irq !=3D3D -ENXIO) > > > > is even easier to understand because for > > > > if (!irq) > > > > they have to check where the value comes from, see it's > > platform_get_irq_optional() and understand that 0 means not-found. >=20 > "vIRQ zero does not exist." With that statement in mind I would expect that a function that gives me an (v)irq number never returns 0. > > This function just adds overhead because as a irq framework user I have > > to understand another function. For me the added benefit is too small to > > justify the additional function. And you break out-of-tree drivers. > > These are all no major counter arguments, but as the advantage isn't > > major either, they still matter. > > > > Best regards > > Uwe > > > > [1] the only annoying thing is the error message. >=20 > So there's still a need for two functions. Or a single function not emitting an error message together with the callers being responsible for calling dev_err(). So the options in my preference order (first is best) are: - Remove the printk from platform_get_irq() and remove platform_get_irq_optional(); - Rename platform_get_irq_optional() to platform_get_irq_silently() - Keep platform_get_irq_optional() as is - Collect underpants - ? - Change semantic of platform_get_irq_optional() Best regards Uwe --=20 Pengutronix e.K. | Uwe Kleine-K=F6nig | Industrial Linux Solutions | https://www.pengutronix.de/ | --daitmup5biyyqkwr Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEfnIqFpAYrP8+dKQLwfwUeK3K7AkFAmHmztAACgkQwfwUeK3K 7AlRQAf6AhYDCHaOxGO6hZ2L8wLnlnF6sFrLHSkHS2GJOuagJzvJ418JJIk3zkkN JJX1REM8rmAXGwIKEat5Ea7goFSWiSw4fr7r3eq/xyxBos5XFH7REZd9Le7ac4e7 BrLcQENmj/gFhEdGk+DOgvOWGWAvWnwp2yKMj33qTbKi72A831OIMsB3+kFwqMt9 f4X3Ng5JNb59Tl0UXy4GhU/8JdsULov6t3SdBUSdZvjE5yXA5IdEctWoZTaW6Rf9 NILpiVlIFQCBsJ9haLtjfp1/EXNVmkb4+5eTiJQndvnAZGDV6FBtRn4PPAYSc3L/ bqjzqdfJVKCdlgfMrOrsPAv2a0DZGQ== =l/Sj -----END PGP SIGNATURE----- --daitmup5biyyqkwr--