]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
power: supply: twl4030-charger: fix OF sibling-node lookup
authorJohan Hovold <johan@kernel.org>
Mon, 27 Aug 2018 08:21:53 +0000 (10:21 +0200)
committerJuerg Haefliger <juergh@canonical.com>
Wed, 24 Jul 2019 01:58:26 +0000 (19:58 -0600)
BugLink: https://bugs.launchpad.net/bugs/1836802
commit 9844fb2e351311210e6660a9a1c62d17424a6145 upstream.

Use the new of_get_compatible_child() helper to lookup the usb sibling
node instead of using of_find_compatible_node(), which searches the
entire tree from a given start node and thus can return an unrelated
(non-sibling) node.

This also addresses a potential use-after-free (e.g. after probe
deferral) as the tree-wide helper drops a reference to its first
argument (i.e. the parent device node).

While at it, also fix the related phy-node reference leak.

Fixes: f5e4edb8c888 ("power: twl4030_charger: find associated phy by more reliable means.")
Cc: stable <stable@vger.kernel.org> # 4.2
Cc: NeilBrown <neilb@suse.de>
Cc: Felipe Balbi <felipe.balbi@linux.intel.com>
Cc: Sebastian Reichel <sre@kernel.org>
Reviewed-by: Sebastian Reichel <sre@kernel.org>
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
drivers/power/supply/twl4030_charger.c

index bbcaee56db9d743b6deb31adce88ee0b5379c56f..b6a7d9f74cf30b0c1d1ab1a9f506206725690210 100644 (file)
@@ -996,12 +996,13 @@ static int twl4030_bci_probe(struct platform_device *pdev)
        if (bci->dev->of_node) {
                struct device_node *phynode;
 
-               phynode = of_find_compatible_node(bci->dev->of_node->parent,
-                                                 NULL, "ti,twl4030-usb");
+               phynode = of_get_compatible_child(bci->dev->of_node->parent,
+                                                 "ti,twl4030-usb");
                if (phynode) {
                        bci->usb_nb.notifier_call = twl4030_bci_usb_ncb;
                        bci->transceiver = devm_usb_get_phy_by_node(
                                bci->dev, phynode, &bci->usb_nb);
+                       of_node_put(phynode);
                        if (IS_ERR(bci->transceiver)) {
                                ret = PTR_ERR(bci->transceiver);
                                if (ret == -EPROBE_DEFER)