Skip to content

Commit 7723f4c

Browse files
bebarinogregkh
authored andcommitted
driver core: platform: Add an error message to platform_get_irq*()
A grep of the kernel shows that many drivers print an error message if they fail to get the irq they're looking for. Furthermore, those drivers all decide to print the device name, or not, and the irq they were requesting, or not, etc. Let's consolidate all these error messages into the API itself, allowing us to get rid of the error messages in each driver. Cc: Rob Herring <[email protected]> Cc: Bartlomiej Zolnierkiewicz <[email protected]> Cc: Javier Martinez Canillas <[email protected]> Cc: Andrzej Hajda <[email protected]> Cc: Mark Brown <[email protected]> Cc: Russell King - ARM Linux <[email protected]> Cc: Marek Szyprowski <[email protected]> Cc: Markus Elfring <[email protected]> Reviewed-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Signed-off-by: Stephen Boyd <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f87da58 commit 7723f4c

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

drivers/base/platform.c

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,7 @@ void __iomem *devm_platform_ioremap_resource(struct platform_device *pdev,
9999
EXPORT_SYMBOL_GPL(devm_platform_ioremap_resource);
100100
#endif /* CONFIG_HAS_IOMEM */
101101

102-
/**
103-
* platform_get_irq - get an IRQ for a device
104-
* @dev: platform device
105-
* @num: IRQ number index
106-
*/
107-
int platform_get_irq(struct platform_device *dev, unsigned int num)
102+
static int __platform_get_irq(struct platform_device *dev, unsigned int num)
108103
{
109104
#ifdef CONFIG_SPARC
110105
/* sparc does not have irqs represented as IORESOURCE_IRQ resources */
@@ -163,6 +158,33 @@ int platform_get_irq(struct platform_device *dev, unsigned int num)
163158
return -ENXIO;
164159
#endif
165160
}
161+
162+
/**
163+
* platform_get_irq - get an IRQ for a device
164+
* @dev: platform device
165+
* @num: IRQ number index
166+
*
167+
* Gets an IRQ for a platform device and prints an error message if finding the
168+
* IRQ fails. Device drivers should check the return value for errors so as to
169+
* not pass a negative integer value to the request_irq() APIs.
170+
*
171+
* Example:
172+
* int irq = platform_get_irq(pdev, 0);
173+
* if (irq < 0)
174+
* return irq;
175+
*
176+
* Return: IRQ number on success, negative error number on failure.
177+
*/
178+
int platform_get_irq(struct platform_device *dev, unsigned int num)
179+
{
180+
int ret;
181+
182+
ret = __platform_get_irq(dev, num);
183+
if (ret < 0 && ret != -EPROBE_DEFER)
184+
dev_err(&dev->dev, "IRQ index %u not found\n", num);
185+
186+
return ret;
187+
}
166188
EXPORT_SYMBOL_GPL(platform_get_irq);
167189

168190
/**
@@ -175,7 +197,7 @@ int platform_irq_count(struct platform_device *dev)
175197
{
176198
int ret, nr = 0;
177199

178-
while ((ret = platform_get_irq(dev, nr)) >= 0)
200+
while ((ret = __platform_get_irq(dev, nr)) >= 0)
179201
nr++;
180202

181203
if (ret == -EPROBE_DEFER)
@@ -228,7 +250,11 @@ int platform_get_irq_byname(struct platform_device *dev, const char *name)
228250
}
229251

230252
r = platform_get_resource_byname(dev, IORESOURCE_IRQ, name);
231-
return r ? r->start : -ENXIO;
253+
if (r)
254+
return r->start;
255+
256+
dev_err(&dev->dev, "IRQ %s not found\n", name);
257+
return -ENXIO;
232258
}
233259
EXPORT_SYMBOL_GPL(platform_get_irq_byname);
234260

0 commit comments

Comments
 (0)