Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F0CCC433EF for ; Fri, 14 Jan 2022 09:26:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239943AbiANJ04 (ORCPT ); Fri, 14 Jan 2022 04:26:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239914AbiANJ0z (ORCPT ); Fri, 14 Jan 2022 04:26:55 -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 52771C061574 for ; Fri, 14 Jan 2022 01:26:55 -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 1n8IqX-0007Po-Mn; Fri, 14 Jan 2022 10:26:09 +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 1n8IqP-00AEBU-7g; Fri, 14 Jan 2022 10:26:00 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1n8IqN-0000tG-Uq; Fri, 14 Jan 2022 10:25:59 +0100 Date: Fri, 14 Jan 2022 10:25:57 +0100 From: Uwe =?utf-8?Q?Kleine-K=C3=B6nig?= To: Sergey Shtylyov Cc: Mark Brown , 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, Jiri Slaby , Linux Kernel Mailing List , Khuong Dinh , Florian Fainelli , Matthias Schiffer , Kamal Dasu , Greg Kroah-Hartman , Lee Jones , Bartosz Golaszewski , Daniel Lezcano , Kishon Vijay Abraham I , Geert Uytterhoeven , "open list:SERIAL DRIVERS" , bcm-kernel-feedback-list , 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 , Takashi Iwai , Peter Korsgaard , William Breathitt Gray , Mark Gross , Hans de Goede , Alex Williamson , Borislav Petkov , Eric Auger , Jakub Kicinski , 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 , "open list:GPIO SUBSYSTEM" , netdev@vger.kernel.org, Yoshihiro Shimoda , Cornelia Huck , Linux MMC List , Joakim Zhang , linux-spi , Linux-Renesas , Vinod Koul , James Morse , Zha Qipeng , Sebastian Reichel , Niklas =?utf-8?Q?S=C3=B6derlund?= , linux-mediatek@lists.infradead.org, Brian Norris , "David S. Miller" Subject: Re: [PATCH 1/2] platform: make platform_get_irq_optional() optional Message-ID: <20220114092557.jrkfx7ihg26ekzci@pengutronix.de> References: <20220110195449.12448-1-s.shtylyov@omp.ru> <20220110195449.12448-2-s.shtylyov@omp.ru> <20220110201014.mtajyrfcfznfhyqm@pengutronix.de> <20220112085009.dbasceh3obfok5dc@pengutronix.de> <20220112213121.5ruae5mxwj6t3qiy@pengutronix.de> <29f0c65d-77f2-e5b2-f6cc-422add8a707d@omp.ru> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="pqpclpjbrmroys3t" Content-Disposition: inline In-Reply-To: <29f0c65d-77f2-e5b2-f6cc-422add8a707d@omp.ru> 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 --pqpclpjbrmroys3t Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello Sergey, On Thu, Jan 13, 2022 at 11:35:34PM +0300, Sergey Shtylyov wrote: > On 1/13/22 12:45 AM, Mark Brown wrote: > >>> To me it sounds much more logical for the driver to check if an > >>> optional irq is non-zero (available) or zero (not available), than to > >>> sprinkle around checks for -ENXIO. In addition, you have to remember > >>> that this one returns -ENXIO, while other APIs use -ENOENT or -ENOSYS > >>> (or some other error code) to indicate absence. I thought not having > >>> to care about the actual error code was the main reason behind the > >>> introduction of the *_optional() APIs. > >=20 > >> No, the main benefit of gpiod_get_optional() (and clk_get_optional()) = is > >> that you can handle an absent GPIO (or clk) as if it were available. >=20 > Hm, I've just looked at these and must note that they match 1:1 with > platform_get_irq_optional(). Unfortunately, we can't however behave the > same way in request_irq() -- because it has to support IRQ0 for the sake > of i8253 drivers in arch/... Let me reformulate your statement to the IMHO equivalent: If you set aside the differences between platform_get_irq_optional() and gpiod_get_optional(), platform_get_irq_optional() is like gpiod_get_optional(). The introduction of gpiod_get_optional() made it possible to simplify the following code: reset_gpio =3D gpiod_get(...) if IS_ERR(reset_gpio): error =3D PTR_ERR(reset_gpio) if error !=3D -ENDEV: return error else: gpiod_set_direction(reset_gpiod, INACTIVE) to reset_gpio =3D gpiod_get_optional(....) if IS_ERR(reset_gpio): return reset_gpio gpiod_set_direction(reset_gpiod, INACTIVE) and I never need to actually know if the reset_gpio actually exists. Either the line is put into its inactive state, or it doesn't exist and then gpiod_set_direction is a noop. For a regulator or a clk this works in a similar way. However for an interupt this cannot work. You will always have to check if the irq is actually there or not because if it's not you cannot just ignore that. So there is no benefit of an optional irq. Leaving error message reporting aside, the introduction of platform_get_irq_optional() allows to change irq =3D platform_get_irq(...); if (irq < 0 && irq !=3D -ENXIO) { return irq; } else if (irq >=3D 0) { ... setup irq operation ... } else { /* irq =3D=3D -ENXIO */ ... setup polling ... } to =09 irq =3D platform_get_irq_optional(...); if (irq < 0 && irq !=3D -ENXIO) { return irq; } else if (irq >=3D 0) { ... setup irq operation ... } else { /* irq =3D=3D -ENXIO */ ... setup polling ... } which isn't a win. When changing the return value as you suggest, it can be changed instead to: irq =3D platform_get_irq_optional(...); if (irq < 0) { return irq; } else if (irq > 0) { ... setup irq operation ... } else { /* irq =3D=3D 0 */ ... setup polling ... } which is a tad nicer. If that is your goal however I ask you to also change the semantic of platform_get_irq() to return 0 on "not found". Note the win is considerably less compared to gpiod_get_optional vs gpiod_get however. And then it still lacks the semantic of a dummy irq which IMHO forfeits the right to call it ..._optional(). Now I'm unwilling to continue the discussion unless there pops up a suggestion that results in a considerable part (say > 10%) of the drivers using platform_get_irq_optional not having to check if the return value corresponds to "not found". Best regards Uwe --=20 Pengutronix e.K. | Uwe Kleine-K=F6nig | Industrial Linux Solutions | https://www.pengutronix.de/ | --pqpclpjbrmroys3t Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEfnIqFpAYrP8+dKQLwfwUeK3K7AkFAmHhQaIACgkQwfwUeK3K 7AmkQAf/d5PfPw0IAOs7Wqvc6r/p6+1tkvEg9YM43cQ03LWApgcX+mJuGNq/lpcb MvZUP4vJwOgXf4HlzKhY5cmrtlcjY+gTojfSCWGvV2oO7t1vx/19Mqh9zY3W297j f5fYMWJx8DicM/I+7Clo5cNGZiBiwEcH3eptaX6YahEQXjSg45gPcXIpGNotj8AO O/Xl9hviFVW48prFLlFLY+qfKNsJPVNtu/Gnl8qdD/USm6Wa7361ko6G32lHIHUf 7NnENwu96Qw92tZN7jHMMmHbiW1xwp5Yu3yd4xf2/h/RBc3iRsgbEoSgjoUYbMgS v/GqERP7XEBCpDmg1fzMNr/LcXeBxQ== =hCsr -----END PGP SIGNATURE----- --pqpclpjbrmroys3t--