USB: phy: am335x-control: fix device and of_node leaks

Make sure to drop the references taken by of_parse_phandle() and
bus_find_device() before returning from am335x_get_phy_control().

Note that there is no guarantee that the devres-managed struct
phy_control will be valid for the lifetime of the sibling phy device
regardless of this change.

Fixes: 3bb869c8b3 ("usb: phy: Add AM335x PHY driver")
Acked-by: Bin Liu <b-liu@ti.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
This commit is contained in:
Johan Hovold 2016-11-01 11:40:25 +01:00 committed by Felipe Balbi
parent f1d3861d63
commit 015105b121

View file

@ -134,10 +134,12 @@ struct phy_control *am335x_get_phy_control(struct device *dev)
return NULL;
dev = bus_find_device(&platform_bus_type, NULL, node, match);
of_node_put(node);
if (!dev)
return NULL;
ctrl_usb = dev_get_drvdata(dev);
put_device(dev);
if (!ctrl_usb)
return NULL;
return &ctrl_usb->phy_ctrl;