[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220112213121.5ruae5mxwj6t3qiy@pengutronix.de>
Date: Wed, 12 Jan 2022 22:31:21 +0100
From: Uwe Kleine-König <u.kleine-koenig@...gutronix.de>
To: Geert Uytterhoeven <geert@...ux-m68k.org>
Cc: Andrew Lunn <andrew@...n.ch>, Ulf Hansson <ulf.hansson@...aro.org>,
Vignesh Raghavendra <vigneshr@...com>,
KVM list <kvm@...r.kernel.org>,
"Rafael J. Wysocki" <rafael@...nel.org>, linux-iio@...r.kernel.org,
Linus Walleij <linus.walleij@...aro.org>,
Amit Kucheria <amitk@...nel.org>,
ALSA Development Mailing List <alsa-devel@...a-project.org>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Joakim Zhang <qiangqing.zhang@....com>,
Guenter Roeck <groeck@...omium.org>,
Thierry Reding <thierry.reding@...il.com>,
MTD Maling List <linux-mtd@...ts.infradead.org>,
Linux I2C <linux-i2c@...r.kernel.org>,
Miquel Raynal <miquel.raynal@...tlin.com>,
linux-phy@...ts.infradead.org, netdev@...r.kernel.org,
linux-spi <linux-spi@...r.kernel.org>,
Jiri Slaby <jirislaby@...nel.org>,
openipmi-developer@...ts.sourceforge.net,
Khuong Dinh <khuong@...amperecomputing.com>,
Florian Fainelli <f.fainelli@...il.com>,
Matthias Schiffer <matthias.schiffer@...tq-group.com>,
Kamal Dasu <kdasu.kdev@...il.com>,
Lee Jones <lee.jones@...aro.org>,
Bartosz Golaszewski <brgl@...ev.pl>,
Daniel Lezcano <daniel.lezcano@...aro.org>,
Kishon Vijay Abraham I <kishon@...com>,
bcm-kernel-feedback-list <bcm-kernel-feedback-list@...adcom.com>,
"open list:SERIAL DRIVERS" <linux-serial@...r.kernel.org>,
Jakub Kicinski <kuba@...nel.org>,
Zhang Rui <rui.zhang@...el.com>,
Jaroslav Kysela <perex@...ex.cz>,
Linux PWM List <linux-pwm@...r.kernel.org>,
Hans de Goede <hdegoede@...hat.com>,
Robert Richter <rric@...nel.org>,
Saravanan Sekar <sravanhome@...il.com>,
Corey Minyard <minyard@....org>,
Linux PM list <linux-pm@...r.kernel.org>,
Mauro Carvalho Chehab <mchehab@...nel.org>,
John Garry <john.garry@...wei.com>,
Peter Korsgaard <peter@...sgaard.com>,
William Breathitt Gray <vilhelm.gray@...il.com>,
Mark Gross <markgross@...nel.org>,
"open list:GPIO SUBSYSTEM" <linux-gpio@...r.kernel.org>,
Alex Williamson <alex.williamson@...hat.com>,
Mark Brown <broonie@...nel.org>,
Borislav Petkov <bp@...en8.de>,
Sebastian Reichel <sre@...nel.org>,
Matthias Brugger <matthias.bgg@...il.com>,
Takashi Iwai <tiwai@...e.com>,
platform-driver-x86@...r.kernel.org,
Benson Leung <bleung@...omium.org>,
Linux ARM <linux-arm-kernel@...ts.infradead.org>,
linux-edac@...r.kernel.org, Tony Luck <tony.luck@...el.com>,
Mun Yew Tham <mun.yew.tham@...el.com>,
Eric Auger <eric.auger@...hat.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Yoshihiro Shimoda <yoshihiro.shimoda.uh@...esas.com>,
Cornelia Huck <cohuck@...hat.com>,
Linux MMC List <linux-mmc@...r.kernel.org>,
Liam Girdwood <lgirdwood@...il.com>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Linux-Renesas <linux-renesas-soc@...r.kernel.org>,
Sergey Shtylyov <s.shtylyov@....ru>,
Vinod Koul <vkoul@...nel.org>,
James Morse <james.morse@....com>,
Zha Qipeng <qipeng.zha@...el.com>,
Pengutronix Kernel Team <kernel@...gutronix.de>,
Richard Weinberger <richard@....at>,
Niklas Söderlund <niklas.soderlund@...natech.se>,
linux-mediatek@...ts.infradead.org,
Brian Norris <computersforpeace@...il.com>,
"David S. Miller" <davem@...emloft.net>
Subject: Re: [PATCH 1/2] platform: make platform_get_irq_optional() optional
On Wed, Jan 12, 2022 at 11:27:02AM +0100, Geert Uytterhoeven wrote:
> Hi Uwe,
>
> On Wed, Jan 12, 2022 at 9:51 AM Uwe Kleine-König
> <u.kleine-koenig@...gutronix.de> wrote:
> > On Wed, Jan 12, 2022 at 09:33:48AM +0100, Geert Uytterhoeven wrote:
> > > On Mon, Jan 10, 2022 at 10:20 PM Andrew Lunn <andrew@...n.ch> wrote:
> > > > On Mon, Jan 10, 2022 at 09:10:14PM +0100, Uwe Kleine-König wrote:
> > > > > On Mon, Jan 10, 2022 at 10:54:48PM +0300, Sergey Shtylyov wrote:
> > > > > > This patch is based on the former Andy Shevchenko's patch:
> > > > > >
> > > > > > https://lore.kernel.org/lkml/20210331144526.19439-1-andriy.shevchenko@linux.intel.com/
> > > > > >
> > > > > > Currently platform_get_irq_optional() returns an error code even if IRQ
> > > > > > resource simply has not been found. It prevents the callers from being
> > > > > > error code agnostic in their error handling:
> > > > > >
> > > > > > ret = platform_get_irq_optional(...);
> > > > > > if (ret < 0 && ret != -ENXIO)
> > > > > > return ret; // respect deferred probe
> > > > > > if (ret > 0)
> > > > > > ...we get an IRQ...
> > > > > >
> > > > > > All other *_optional() APIs seem to return 0 or NULL in case an optional
> > > > > > resource is not available. Let's follow this good example, so that the
> > > > > > callers would look like:
> > > > > >
> > > > > > ret = platform_get_irq_optional(...);
> > > > > > if (ret < 0)
> > > > > > return ret;
> > > > > > if (ret > 0)
> > > > > > ...we get an IRQ...
> > > > >
> > > > > The difference to gpiod_get_optional (and most other *_optional) is that
> > > > > you can use the NULL value as if it were a valid GPIO.
> > > > >
> > > > > As this isn't given with for irqs, I don't think changing the return
> > > > > value has much sense.
> > > >
> > > > We actually want platform_get_irq_optional() to look different to all
> > > > the other _optional() methods because it is not equivalent. If it
> > > > looks the same, developers will assume it is the same, and get
> > > > themselves into trouble.
> > >
> > > Developers already assume it is the same, and thus forget they have
> > > to check against -ENXIO instead of zero.
I agree that -ENXIO is unfortunate and -ENOENT would be more in line
with other functions. I assume it's insane to want to change that.
> > Is this an ack for renaming platform_get_irq_optional() to
> > platform_get_irq_silent()?
>
> No it isn't ;-)
>
> If an optional IRQ is not present, drivers either just ignore it (e.g.
> for devices that can have multiple interrupts or a single muxed IRQ),
> or they have to resort to polling. For the latter, fall-back handling
> is needed elsewhere in the driver.
I think irq are not suitable for such a dummy handling. For clocks or
GPIOs there are cases where just doing nothing in the absence of a
certain optional clock or GPIO is fine.
I checked a few users of platform_get_irq_optional() and I didn't find a
single one that doesn't need to differentiate the irq and the no-irq
case later. Do you know one? If you do, isn't that so exceptional that
it doesn't justify the idea of a dummy irq value? So until proven
otherwise I think platform_get_irq_optional() just isn't in the spirit
of clk_get_optional() and gpiod_get_optional() because there are no use
cases where a dummy value would be good enough. (Even if request_irq
would be a noop for a dummy irq value.)
The motivation why platform_get_irq_optional() was introduced was just
that platform_get_irq() started to emit an error message (in commit
7723f4c5ecdb8d832f049f8483beb0d1081cedf6) and the (proportional) few
drivers where the error message was bad needed a variant that doesn't
emit the error message. Look at
31a8d8fa84c51d3ab00bf059158d5de6178cf890, the motivation to use
platform_get_irq_optional() wasn't that it simplifies handling in the
driver, but that it doesn't emit an error message. Or
8f5783ad9eb83747471f61f94dbe209fb9fb8a7d, or
2fd276c3ee4bd42eb034f8954964a5ae74187c6b, or
55cc33fab5ac9f7e2a97aa7c564e8b35355886d5. Just look at the output of git
log -Splatform_get_irq_optional to find some more.
That convinces me, that platform_get_irq_optional() is a bad name. The
only difference to platform_get_irq is that it's silent. And returning
a dummy irq value (which would make it aligned with the other _optional
functions) isn't possible.
> 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.
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.
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | https://www.pengutronix.de/ |
Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)
Powered by blists - more mailing lists