1
0
Fork 0

phy: tegra: fix device-tree node lookups

commit 046046737b upstream.

Fix child-node lookups during probe, which ended up searching the whole
device tree depth-first starting at the parents rather than just
matching on their children.

To make things worse, some parent nodes could end up being being
prematurely freed (by tegra_xusb_pad_register()) as
of_find_node_by_name() drops a reference to its first argument.

Fixes: 53d2a715c2 ("phy: Add Tegra XUSB pad controller support")
Cc: Thierry Reding <treding@nvidia.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
pull/10/head
Johan Hovold 2017-11-15 10:43:16 +01:00 committed by Greg Kroah-Hartman
parent d87f1bc7d1
commit f3f5fa872d
1 changed files with 29 additions and 29 deletions

View File

@ -75,14 +75,14 @@ MODULE_DEVICE_TABLE(of, tegra_xusb_padctl_of_match);
static struct device_node * static struct device_node *
tegra_xusb_find_pad_node(struct tegra_xusb_padctl *padctl, const char *name) tegra_xusb_find_pad_node(struct tegra_xusb_padctl *padctl, const char *name)
{ {
/* struct device_node *pads, *np;
* of_find_node_by_name() drops a reference, so make sure to grab one.
*/
struct device_node *np = of_node_get(padctl->dev->of_node);
np = of_find_node_by_name(np, "pads"); pads = of_get_child_by_name(padctl->dev->of_node, "pads");
if (np) if (!pads)
np = of_find_node_by_name(np, name); return NULL;
np = of_get_child_by_name(pads, name);
of_node_put(pads);
return np; return np;
} }
@ -90,16 +90,16 @@ tegra_xusb_find_pad_node(struct tegra_xusb_padctl *padctl, const char *name)
static struct device_node * static struct device_node *
tegra_xusb_pad_find_phy_node(struct tegra_xusb_pad *pad, unsigned int index) tegra_xusb_pad_find_phy_node(struct tegra_xusb_pad *pad, unsigned int index)
{ {
/* struct device_node *np, *lanes;
* of_find_node_by_name() drops a reference, so make sure to grab one.
*/
struct device_node *np = of_node_get(pad->dev.of_node);
np = of_find_node_by_name(np, "lanes"); lanes = of_get_child_by_name(pad->dev.of_node, "lanes");
if (!np) if (!lanes)
return NULL; return NULL;
return of_find_node_by_name(np, pad->soc->lanes[index].name); np = of_get_child_by_name(lanes, pad->soc->lanes[index].name);
of_node_put(lanes);
return np;
} }
static int static int
@ -195,7 +195,7 @@ int tegra_xusb_pad_register(struct tegra_xusb_pad *pad,
unsigned int i; unsigned int i;
int err; int err;
children = of_find_node_by_name(pad->dev.of_node, "lanes"); children = of_get_child_by_name(pad->dev.of_node, "lanes");
if (!children) if (!children)
return -ENODEV; return -ENODEV;
@ -444,21 +444,21 @@ static struct device_node *
tegra_xusb_find_port_node(struct tegra_xusb_padctl *padctl, const char *type, tegra_xusb_find_port_node(struct tegra_xusb_padctl *padctl, const char *type,
unsigned int index) unsigned int index)
{ {
/* struct device_node *ports, *np;
* of_find_node_by_name() drops a reference, so make sure to grab one. char *name;
*/
struct device_node *np = of_node_get(padctl->dev->of_node);
np = of_find_node_by_name(np, "ports"); ports = of_get_child_by_name(padctl->dev->of_node, "ports");
if (np) { if (!ports)
char *name; return NULL;
name = kasprintf(GFP_KERNEL, "%s-%u", type, index); name = kasprintf(GFP_KERNEL, "%s-%u", type, index);
if (!name) if (!name) {
return ERR_PTR(-ENOMEM); of_node_put(ports);
np = of_find_node_by_name(np, name); return ERR_PTR(-ENOMEM);
kfree(name);
} }
np = of_get_child_by_name(ports, name);
kfree(name);
of_node_put(ports);
return np; return np;
} }
@ -847,7 +847,7 @@ static void tegra_xusb_remove_ports(struct tegra_xusb_padctl *padctl)
static int tegra_xusb_padctl_probe(struct platform_device *pdev) static int tegra_xusb_padctl_probe(struct platform_device *pdev)
{ {
struct device_node *np = of_node_get(pdev->dev.of_node); struct device_node *np = pdev->dev.of_node;
const struct tegra_xusb_padctl_soc *soc; const struct tegra_xusb_padctl_soc *soc;
struct tegra_xusb_padctl *padctl; struct tegra_xusb_padctl *padctl;
const struct of_device_id *match; const struct of_device_id *match;
@ -855,7 +855,7 @@ static int tegra_xusb_padctl_probe(struct platform_device *pdev)
int err; int err;
/* for backwards compatibility with old device trees */ /* for backwards compatibility with old device trees */
np = of_find_node_by_name(np, "pads"); np = of_get_child_by_name(np, "pads");
if (!np) { if (!np) {
dev_warn(&pdev->dev, "deprecated DT, using legacy driver\n"); dev_warn(&pdev->dev, "deprecated DT, using legacy driver\n");
return tegra_xusb_padctl_legacy_probe(pdev); return tegra_xusb_padctl_legacy_probe(pdev);