linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] of: irq: don't return 0 from of_irq_get()
@ 2016-05-28 21:53 Sergei Shtylyov
  2016-06-03 12:14 ` Rob Herring
  0 siblings, 1 reply; 4+ messages in thread
From: Sergei Shtylyov @ 2016-05-28 21:53 UTC (permalink / raw)
  To: grant.likely, robh+dt, devicetree, frowand.list; +Cc: linux-kernel

of_irq_get() returns 0 iff irq_create_of_mapping() call fails. Returning
both error code  and 0 on failure is a sign of a misdesigned API. Return
-ENXIO instead like one of the callers, platform_get_irq(), does; fix up
the kernel-doc as well...

Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>

---
The patch is against Linus' 'linux.git' repo (Grant Likely's repo is outdated)
plus the patch just posted, however it's intended to be merged in the next
kernel release (v4.8-rc1)...

 drivers/of/irq.c       |   13 ++++++-------
 include/linux/of_irq.h |    4 ++--
 2 files changed, 8 insertions(+), 9 deletions(-)

Index: linux/drivers/of/irq.c
===================================================================
--- linux.orig/drivers/of/irq.c
+++ linux/drivers/of/irq.c
@@ -390,9 +390,8 @@ EXPORT_SYMBOL_GPL(of_irq_to_resource);
  * @dev: pointer to device tree node
  * @index: zero-based index of the IRQ
  *
- * Returns Linux IRQ number on success, or 0 on the IRQ mapping failure, or
- * -EPROBE_DEFER if the IRQ domain is not yet created, or error code in case
- * of any other failure.
+ * Returns Linux IRQ number on success, or -EPROBE_DEFER if the IRQ domain
+ * is not yet created, or error code in case of any other failure.
  */
 int of_irq_get(struct device_node *dev, int index)
 {
@@ -408,7 +407,8 @@ int of_irq_get(struct device_node *dev,
 	if (!domain)
 		return -EPROBE_DEFER;
 
-	return irq_create_of_mapping(&oirq);
+	rc = irq_create_of_mapping(&oirq);
+	return rc > 0 ? rc : -ENXIO;
 }
 EXPORT_SYMBOL_GPL(of_irq_get);
 
@@ -417,9 +417,8 @@ EXPORT_SYMBOL_GPL(of_irq_get);
  * @dev: pointer to device tree node
  * @name: IRQ name
  *
- * Returns Linux IRQ number on success, or 0 on the IRQ mapping failure, or
- * -EPROBE_DEFER if the IRQ domain is not yet created, or error code in case
- * of any other failure.
+ * Returns Linux IRQ number on success, or -EPROBE_DEFER if the IRQ domain
+ * is not yet created, or error code in case of any other failure.
  */
 int of_irq_get_byname(struct device_node *dev, const char *name)
 {
Index: linux/include/linux/of_irq.h
===================================================================
--- linux.orig/include/linux/of_irq.h
+++ linux/include/linux/of_irq.h
@@ -61,11 +61,11 @@ static inline int of_irq_count(struct de
 }
 static inline int of_irq_get(struct device_node *dev, int index)
 {
-	return 0;
+	return -ENXIO;
 }
 static inline int of_irq_get_byname(struct device_node *dev, const char *name)
 {
-	return 0;
+	return -ENXIO;
 }
 static inline int of_irq_to_resource_table(struct device_node *dev,
 					   struct resource *res, int nr_irqs)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] of: irq: don't return 0 from of_irq_get()
  2016-05-28 21:53 [PATCH] of: irq: don't return 0 from of_irq_get() Sergei Shtylyov
@ 2016-06-03 12:14 ` Rob Herring
  2016-06-10 12:14   ` Sergei Shtylyov
  0 siblings, 1 reply; 4+ messages in thread
From: Rob Herring @ 2016-06-03 12:14 UTC (permalink / raw)
  To: Sergei Shtylyov; +Cc: grant.likely, devicetree, frowand.list, linux-kernel

On Sun, May 29, 2016 at 12:53:08AM +0300, Sergei Shtylyov wrote:
> of_irq_get() returns 0 iff irq_create_of_mapping() call fails. Returning
> both error code  and 0 on failure is a sign of a misdesigned API. Return
> -ENXIO instead like one of the callers, platform_get_irq(), does; fix up
> the kernel-doc as well...
> 
> Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>

So I think this is done this way because of the variation in NO_IRQ 
definition across architectures. But then again, of_irq_get is 
relatively new.

Rob

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] of: irq: don't return 0 from of_irq_get()
  2016-06-03 12:14 ` Rob Herring
@ 2016-06-10 12:14   ` Sergei Shtylyov
  2016-06-10 12:55     ` Rob Herring
  0 siblings, 1 reply; 4+ messages in thread
From: Sergei Shtylyov @ 2016-06-10 12:14 UTC (permalink / raw)
  To: Rob Herring; +Cc: grant.likely, devicetree, frowand.list, linux-kernel

On 6/3/2016 3:14 PM, Rob Herring wrote:

>> of_irq_get() returns 0 iff irq_create_of_mapping() call fails. Returning
>> both error code  and 0 on failure is a sign of a misdesigned API. Return
>> -ENXIO instead like one of the callers, platform_get_irq(), does; fix up
>> the kernel-doc as well...
>>
>> Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
>
> So I think this is done this way because of the variation in NO_IRQ
> definition across architectures.

    I remember that NO_IRQ is "considered harmful" by Linus. Actually, I'm nit 
sure what you mean, could you elaborate on that?

> But then again, of_irq_get is
> relatively new.

> Rob

MBR, Sergei

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] of: irq: don't return 0 from of_irq_get()
  2016-06-10 12:14   ` Sergei Shtylyov
@ 2016-06-10 12:55     ` Rob Herring
  0 siblings, 0 replies; 4+ messages in thread
From: Rob Herring @ 2016-06-10 12:55 UTC (permalink / raw)
  To: Sergei Shtylyov; +Cc: Grant Likely, devicetree, Frank Rowand, linux-kernel

On Fri, Jun 10, 2016 at 7:14 AM, Sergei Shtylyov
<sergei.shtylyov@cogentembedded.com> wrote:
> On 6/3/2016 3:14 PM, Rob Herring wrote:
>
>>> of_irq_get() returns 0 iff irq_create_of_mapping() call fails. Returning
>>> both error code  and 0 on failure is a sign of a misdesigned API. Return
>>> -ENXIO instead like one of the callers, platform_get_irq(), does; fix up
>>> the kernel-doc as well...
>>>
>>> Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
>>
>>
>> So I think this is done this way because of the variation in NO_IRQ
>> definition across architectures.
>
>
>    I remember that NO_IRQ is "considered harmful" by Linus. Actually, I'm
> nit sure what you mean, could you elaborate on that?

Calling locations could handle 0 vs. negative differently. The return
value propagates as well, so you can't easily audit how it is handled.
I'm being paranoid, but we need a better reason than "misdesigned
API". I'm pretty sure we misdesigned it on purpose.

Rob

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-06-10 12:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-28 21:53 [PATCH] of: irq: don't return 0 from of_irq_get() Sergei Shtylyov
2016-06-03 12:14 ` Rob Herring
2016-06-10 12:14   ` Sergei Shtylyov
2016-06-10 12:55     ` Rob Herring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).