Re: [PATCH 1/2] platform: make platform_get_irq_optional() optional (summary)

From: Uwe Kleine-König
Date: Sat Jan 15 2022 - 13:38:09 EST


Hello,

I'm trying to objectively summarize the discussions in this thread in
the hope this helps finding a way that most people can live with.

First a description of the status quo:

There are several function pairs *get() and *get_optional() that however
are different in various aspects. Their relevant properties are listes
in the following table. Ideally each line had only identical entries.

| clk_get | gpiod_get | platform_get_irq | regulator_get |
return value | | | | |
on not-found | ERR_PTR(-ENOENT) | ERR_PTR(-ENOENT) | -ENXIO | dummy[1] |
(plain get) | | | | |
| | | | |
return value | | | | |
on not-found | dummy[1] | dummy[1] | -ENXIO | ERR_PTR(-ENOENT) |
(get_optional) | | | | |
| | | | |
emits an error message | | | | |
on error (including | no | no | yes[2] | no |
not-found) | | | | |
| | | | |
get_optional emits an error | | | | |
message on error (including | no | no | no | no |
not-found) | | | | |
| | | | |
summary: | returning a dummy | returning a dummy | doesn't emit an | returning error code |
*_get_optional() differs from | on not-found | on not-found | error message | on not-found |
*_get by: | | | | |


[1] the dummy value is a valid resource descriptor, the API functions
are a noop for this dummy value. This dummy value is NULL for
all three subsystems.
[2] no error is printed for -EPROBE_DEFER.

The inversion between clk+gpio vs. regulator is unforunate, swaping one
or the other would be good for consistency, but this isn't the topic of
this thread. Only so much: It's not agreed upon which variant is the
better one and the difference is of historical origin.

There are now different suggestions to improve the situation regarding
platform_get_irq() compared to the other functions:

a) by Sergey
platform_get_irq_optional() is changed to return 0 on not-found.

b) by Uwe
rename platform_get_irq_optional() to platform_get_irq_silent()

The argument pro a) is:

platform_get_irq_optional() is aligned to clk_get() and
gpiod_get() by returning 0 on not-found.

The argument contra a)

The return value 0 for platform_get_irq() is only syntactically
nearer to the dummy value of clk_get() and gpiod_get(). A dummy
value isn't available and probably not sensible to introduce for
irq because most drivers have to check for the not-found
situation anyhow to setup polling.

The argument pro b) is:

The relevant difference between platform_get_irq() and its
optional variant is that the latter is silent. This is a
different concept for the meaning of optional compared to the
other *_get_optional().

The argument contra b) is:

The chosen name is bad, because driver authors might wonder what
a silent irq is.

---- end of summary

A possible compromise: We can have both. We rename
platform_get_irq_optional() to platform_get_irq_silent() (or
platform_get_irq_silently() if this is preferred) and once all users are
are changed (which can be done mechanically), we reintroduce a
platform_get_irq_optional() with Sergey's suggested semantic (i.e.
return 0 on not-found, no error message printking).

Best regards
Uwe

--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | https://www.pengutronix.de/ |

Attachment: signature.asc
Description: PGP signature