diff --git a/drivers/of/irq.c b/drivers/of/irq.c index 109c54f34647..4fbbd13f4d0a 100644 --- a/drivers/of/irq.c +++ b/drivers/of/irq.c @@ -765,34 +765,27 @@ void __init of_irq_init(const struct of_device_id *matches) } } -static int of_check_msi_parent(struct device_node *dev_node, struct device_node **msi_node) +static int of_check_msi_parent(struct device_node *dev_node, struct device_node **msi_node, + struct of_phandle_args *msi_spec) { - struct of_phandle_args msi_spec; int ret; /* * An msi-parent phandle with a missing or == 0 #msi-cells * property identifies a 1:1 ID translation mapping. * - * Set the msi controller node if the firmware matches this - * condition. + * @msi_spec keeps a reference to the target node whenever the + * phandle parses, -EINVAL included, and the caller releases it. */ ret = of_parse_phandle_with_optional_args(dev_node, "msi-parent", "#msi-cells", - 0, &msi_spec); + 0, msi_spec); if (ret) return ret; - if ((*msi_node && *msi_node != msi_spec.np) || msi_spec.args_count != 0) - ret = -EINVAL; + if ((*msi_node && *msi_node != msi_spec->np) || msi_spec->args_count != 0) + return -EINVAL; - if (!ret && !*msi_node) { - /* Return with a node reference held */ - *msi_node = msi_spec.np; - return 0; - } - of_node_put(msi_spec.np); - - return ret; + return 0; } /** @@ -806,7 +799,9 @@ static int of_check_msi_parent(struct device_node *dev_node, struct device_node * @id_in: Device ID. * * Walk up the device hierarchy looking for devices with a "msi-map" - * or "msi-parent" property. If found, apply the mapping to @id_in. + * or "msi-parent" property. If found, apply the mapping to @id_in. With + * @msi_np non-NULL, a device declaring an msi-parent ends the walk, usable + * or not. * * Returns: The mapped MSI id. */ @@ -821,6 +816,7 @@ u32 of_msi_xlate(struct device *dev, struct device_node **msi_np, u32 id_in) */ for (parent_dev = dev; parent_dev; parent_dev = parent_dev->parent) { struct of_phandle_args msi_spec = {}; + int ret; if (!of_map_msi_id(parent_dev->of_node, id_in, msi_np, &msi_spec)) { if (msi_spec.np) { @@ -835,8 +831,17 @@ u32 of_msi_xlate(struct device *dev, struct device_node **msi_np, u32 id_in) break; } /* -ENODEV: msi-map absent → check for msi-parent */ - if (msi_np && !of_check_msi_parent(parent_dev->of_node, msi_np)) + if (!msi_np) + continue; + + ret = of_check_msi_parent(parent_dev->of_node, msi_np, &msi_spec); + if (msi_spec.np) { + /* A declared msi-parent names the controller, usable or not */ + if (!ret && !*msi_np) + *msi_np = of_node_get(msi_spec.np); + of_node_put(msi_spec.np); break; + } } return id_out; }