Skip to contentSkip to conversation

platform: don't return 0 from platform_get_irq[_byname]() on error

PATCH Superseded Sergei Shtylyov 1 participant 2 messages May 28, 2016 – Jun 10, 2016 Driver core

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 platform: don't return 0 from platform_get_irq[_byname]() on error

of_irq_get[_byname]() return 0 iff irq_create_of_mapping() call fails. Returning both error code and 0 on failure is a sign of a misdesigned API. We should rely on the platform IRQ resource in this case, not return 0, especially as 0 can be a valid IRQ resource too...

Fixes aff008ad813c ("platform_get_irq: Revert to platform_get_resource if of_irq_get fails")

---
The patch is against the 'driver-core-linus' branch of Greg KH's 'driver-core.git' repo.

 drivers/base/platform.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/base/platform.c +2 -2
Index: driver-core/drivers/base/platform.c
===================================================================
@@ -97,7 +97,7 @@ int platform_get_irq(struct platform_dev
 		int ret;
 
 		ret = of_irq_get(dev->dev.of_node, num);
-		if (ret >= 0 || ret == -EPROBE_DEFER)
+		if (ret > 0 || ret == -EPROBE_DEFER)
 			return ret;
 	}
 
@@ -175,7 +175,7 @@ int platform_get_irq_byname(struct platf
 		int ret;
 
 		ret = of_irq_get_byname(dev->dev.of_node, name);
-		if (ret >= 0 || ret == -EPROBE_DEFER)
+		if (ret > 0 || ret == -EPROBE_DEFER)
 			return ret;
 	}
 
#1 lore raw

Hello.

Quoted 4 lines · Sergei Shtylyov

of_irq_get[_byname]() return 0 iff irq_create_of_mapping() call fails. Returning both error code and 0 on failure is a sign of a misdesigned API. We should rely on the platform IRQ resource in this case, not return 0, especially as 0 can be a valid IRQ resource too...

Actually, I wanted to say that returning 0 on error makes the error check
unnecessarily complex and error prone bu fogrgot about that when writing the changelog. Let me know what you think...

Quoted 3 lines
Fixes aff008ad813c ("platform_get_irq: Revert to platform_get_resource if of_irq_get fails")

[...]

MBR, Sergei