Skip to content

Commit 9844fb2

Browse files
jhovoldrobherring
authored andcommitted
power: supply: twl4030-charger: fix OF sibling-node lookup
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: f5e4edb ("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>
1 parent 5bf5977 commit 9844fb2

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/power/supply/twl4030_charger.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -996,12 +996,13 @@ static int twl4030_bci_probe(struct platform_device *pdev)
996996
if (bci->dev->of_node) {
997997
struct device_node *phynode;
998998

999-
phynode = of_find_compatible_node(bci->dev->of_node->parent,
1000-
NULL, "ti,twl4030-usb");
999+
phynode = of_get_compatible_child(bci->dev->of_node->parent,
1000+
"ti,twl4030-usb");
10011001
if (phynode) {
10021002
bci->usb_nb.notifier_call = twl4030_bci_usb_ncb;
10031003
bci->transceiver = devm_usb_get_phy_by_node(
10041004
bci->dev, phynode, &bci->usb_nb);
1005+
of_node_put(phynode);
10051006
if (IS_ERR(bci->transceiver)) {
10061007
ret = PTR_ERR(bci->transceiver);
10071008
if (ret == -EPROBE_DEFER)

0 commit comments

Comments
 (0)