of/irq: of_irq_find_parent: check for parent equal to child

An interrupt controller may often implicitly inherit itself from a parent
node when in fact the controller is the interrupt root controller. Guard
against the case of child == parent and return NULL in this case.

This can also be fixed by adding an explicit "interrupt-parent;" to a root
interrupt controller node.

Based on code from Grant Likely.

Signed-off-by: Rob Herring <rob.herring@calxeda.com>
Cc: Grant Likely <grant.likely@secretlab.ca>
This commit is contained in:
Rob Herring 2011-09-20 13:02:54 -05:00
parent f910b831c9
commit dc93728084

View file

@ -58,27 +58,27 @@ EXPORT_SYMBOL_GPL(irq_of_parse_and_map);
*/ */
struct device_node *of_irq_find_parent(struct device_node *child) struct device_node *of_irq_find_parent(struct device_node *child)
{ {
struct device_node *p; struct device_node *p, *c = child;
const __be32 *parp; const __be32 *parp;
if (!of_node_get(child)) if (!of_node_get(c))
return NULL; return NULL;
do { do {
parp = of_get_property(child, "interrupt-parent", NULL); parp = of_get_property(c, "interrupt-parent", NULL);
if (parp == NULL) if (parp == NULL)
p = of_get_parent(child); p = of_get_parent(c);
else { else {
if (of_irq_workarounds & OF_IMAP_NO_PHANDLE) if (of_irq_workarounds & OF_IMAP_NO_PHANDLE)
p = of_node_get(of_irq_dflt_pic); p = of_node_get(of_irq_dflt_pic);
else else
p = of_find_node_by_phandle(be32_to_cpup(parp)); p = of_find_node_by_phandle(be32_to_cpup(parp));
} }
of_node_put(child); of_node_put(c);
child = p; c = p;
} while (p && of_get_property(p, "#interrupt-cells", NULL) == NULL); } while (p && of_get_property(p, "#interrupt-cells", NULL) == NULL);
return p; return (p == child) ? NULL : p;
} }
/** /**