Skip to content

Commit

Permalink
irq/irq_domain: Quit ignoring error returns from irq_alloc_desc_from().
Browse files Browse the repository at this point in the history
In commit 4bbdd45 (irq_domain/powerpc: eliminate irq_map; use
irq_alloc_desc() instead) code was added that ignores error returns
from irq_alloc_desc_from() by (silently) casting the return value to
unsigned.  The negitive value error return now suddenly looks like a
valid irq number.

Commits cc79ca6 (irq_domain: Move irq_domain code from powerpc to
kernel/irq) and 1bc04f2 (irq_domain: Add support for base irq and
hwirq in legacy mappings) move this code to its current location in
irqdomain.c

The result of all of this is a null pointer dereference OOPS if one of
the error cases is hit.

The fix: Don't cast away the negativeness of the return value and then
check for errors.

Signed-off-by: David Daney <david.daney@cavium.com>
Acked-by: Rob Herring <rob.herring@calxeda.com>
[grant.likely: dropped addition of new 'irq' variable]
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
  • Loading branch information
David Daney authored and Grant Likely committed Apr 11, 2012
1 parent 0034102 commit 5b7526e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions kernel/irq/irqdomain.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ unsigned int irq_create_direct_mapping(struct irq_domain *domain)
unsigned int irq_create_mapping(struct irq_domain *domain,
irq_hw_number_t hwirq)
{
unsigned int virq, hint;
unsigned int hint;
int virq;

pr_debug("irq: irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq);

Expand Down Expand Up @@ -381,9 +382,9 @@ unsigned int irq_create_mapping(struct irq_domain *domain,
if (hint == 0)
hint++;
virq = irq_alloc_desc_from(hint, 0);
if (!virq)
if (virq <= 0)
virq = irq_alloc_desc_from(1, 0);
if (!virq) {
if (virq <= 0) {
pr_debug("irq: -> virq allocation failed\n");
return 0;
}
Expand Down

0 comments on commit 5b7526e

Please sign in to comment.