Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Andres Salomon and committed by
Grant Likely
52f6537c e2f2a93b

+45 -7
+39
drivers/of/irq.c
··· 24 24 #include <linux/of_irq.h> 25 25 #include <linux/string.h> 26 26 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 + 27 32 /** 28 33 * irq_of_parse_and_map - Parse and map an interrupt into linux virq space 29 34 * @device: Device node of the device whose interrupt is to be mapped ··· 352 347 return irq; 353 348 } 354 349 EXPORT_SYMBOL_GPL(of_irq_to_resource); 350 + 351 + /** 352 + * of_irq_count - Count the number of IRQs a node uses 353 + * @dev: pointer to device tree node 354 + */ 355 + int of_irq_count(struct device_node *dev) 356 + { 357 + int nr = 0; 358 + 359 + while (of_irq_to_resource(dev, nr, NULL) != NO_IRQ) 360 + nr++; 361 + 362 + return nr; 363 + } 364 + 365 + /** 366 + * of_irq_to_resource_table - Fill in resource table with node's IRQ info 367 + * @dev: pointer to device tree node 368 + * @res: array of resources to fill in 369 + * @nr_irqs: the number of IRQs (and upper bound for num of @res elements) 370 + * 371 + * Returns the size of the filled in table (up to @nr_irqs). 372 + */ 373 + int of_irq_to_resource_table(struct device_node *dev, struct resource *res, 374 + int nr_irqs) 375 + { 376 + int i; 377 + 378 + for (i = 0; i < nr_irqs; i++, res++) 379 + if (of_irq_to_resource(dev, i, res) == NO_IRQ) 380 + break; 381 + 382 + return i; 383 + }
+3 -7
drivers/of/platform.c
··· 584 584 struct device *parent) 585 585 { 586 586 struct platform_device *dev; 587 - int rc, i, num_reg = 0, num_irq = 0; 587 + int rc, i, num_reg = 0, num_irq; 588 588 struct resource *res, temp_res; 589 589 590 590 /* First count how many resources are needed */ 591 591 while (of_address_to_resource(np, num_reg, &temp_res) == 0) 592 592 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); 595 594 596 595 /* Allocate memory for both the struct device and the resource table */ 597 596 dev = kzalloc(sizeof(*dev) + (sizeof(*res) * (num_reg + num_irq)), ··· 607 608 rc = of_address_to_resource(np, i, res); 608 609 WARN_ON(rc); 609 610 } 610 - for (i = 0; i < num_irq; i++, res++) { 611 - rc = of_irq_to_resource(np, i, res); 612 - WARN_ON(rc == NO_IRQ); 613 - } 611 + WARN_ON(of_irq_to_resource_table(np, res, num_irq) != num_irq); 614 612 } 615 613 616 614 dev->dev.of_node = of_node_get(np);
+3
include/linux/of_irq.h
··· 64 64 unsigned int intsize); 65 65 extern int of_irq_to_resource(struct device_node *dev, int index, 66 66 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); 67 70 68 71 #endif /* CONFIG_OF_IRQ */ 69 72 #endif /* CONFIG_OF */