Skip to content

Commit 52f6537

Browse files
dilingerglikely
authored andcommitted
of/irq: remove references to NO_IRQ in drivers/of/platform.c
Instead of referencing NO_IRQ in platform.c, define some helper functions in irq.c to call instead from platform.c. Keep NO_IRQ usage local to irq.c, and define NO_IRQ if not defined in headers. Signed-off-by: Andres Salomon <dilinger@queued.net> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
1 parent e2f2a93 commit 52f6537

3 files changed

Lines changed: 45 additions & 7 deletions

File tree

‎drivers/of/irq.c‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
#include <linux/of_irq.h>
2525
#include <linux/string.h>
2626

27+
/* For archs that don't support NO_IRQ (such as x86), provide a dummy value */
28+
#ifndef NO_IRQ
29+
#define NO_IRQ 0
30+
#endif
31+
2732
/**
2833
* irq_of_parse_and_map - Parse and map an interrupt into linux virq space
2934
* @device: Device node of the device whose interrupt is to be mapped
@@ -347,3 +352,37 @@ int of_irq_to_resource(struct device_node *dev, int index, struct resource *r)
347352
return irq;
348353
}
349354
EXPORT_SYMBOL_GPL(of_irq_to_resource);
355+
356+
/**
357+
* of_irq_count - Count the number of IRQs a node uses
358+
* @dev: pointer to device tree node
359+
*/
360+
int of_irq_count(struct device_node *dev)
361+
{
362+
int nr = 0;
363+
364+
while (of_irq_to_resource(dev, nr, NULL) != NO_IRQ)
365+
nr++;
366+
367+
return nr;
368+
}
369+
370+
/**
371+
* of_irq_to_resource_table - Fill in resource table with node's IRQ info
372+
* @dev: pointer to device tree node
373+
* @res: array of resources to fill in
374+
* @nr_irqs: the number of IRQs (and upper bound for num of @res elements)
375+
*
376+
* Returns the size of the filled in table (up to @nr_irqs).
377+
*/
378+
int of_irq_to_resource_table(struct device_node *dev, struct resource *res,
379+
int nr_irqs)
380+
{
381+
int i;
382+
383+
for (i = 0; i < nr_irqs; i++, res++)
384+
if (of_irq_to_resource(dev, i, res) == NO_IRQ)
385+
break;
386+
387+
return i;
388+
}

‎drivers/of/platform.c‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -584,14 +584,13 @@ struct platform_device *of_device_alloc(struct device_node *np,
584584
struct device *parent)
585585
{
586586
struct platform_device *dev;
587-
int rc, i, num_reg = 0, num_irq = 0;
587+
int rc, i, num_reg = 0, num_irq;
588588
struct resource *res, temp_res;
589589

590590
/* First count how many resources are needed */
591591
while (of_address_to_resource(np, num_reg, &temp_res) == 0)
592592
num_reg++;
593-
while (of_irq_to_resource(np, num_irq, &temp_res) != NO_IRQ)
594-
num_irq++;
593+
num_irq = of_irq_count(np);
595594

596595
/* Allocate memory for both the struct device and the resource table */
597596
dev = kzalloc(sizeof(*dev) + (sizeof(*res) * (num_reg + num_irq)),
@@ -608,10 +607,7 @@ struct platform_device *of_device_alloc(struct device_node *np,
608607
rc = of_address_to_resource(np, i, res);
609608
WARN_ON(rc);
610609
}
611-
for (i = 0; i < num_irq; i++, res++) {
612-
rc = of_irq_to_resource(np, i, res);
613-
WARN_ON(rc == NO_IRQ);
614-
}
610+
WARN_ON(of_irq_to_resource_table(np, res, num_irq) != num_irq);
615611
}
616612

617613
dev->dev.of_node = of_node_get(np);

‎include/linux/of_irq.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ extern unsigned int irq_create_of_mapping(struct device_node *controller,
6464
unsigned int intsize);
6565
extern int of_irq_to_resource(struct device_node *dev, int index,
6666
struct resource *r);
67+
extern int of_irq_count(struct device_node *dev);
68+
extern int of_irq_to_resource_table(struct device_node *dev,
69+
struct resource *res, int nr_irqs);
6770

6871
#endif /* CONFIG_OF_IRQ */
6972
#endif /* CONFIG_OF */

0 commit comments

Comments
 (0)