Skip to content

Commit ac63043

Browse files
jhovoldrobherring
authored andcommitted
net: stmmac: dwmac-sun8i: fix OF child-node lookup
Use the new of_get_compatible_child() helper to lookup the mdio-internal child node instead of using of_find_compatible_node(), which searches the entire tree from a given start node and thus can return an unrelated (i.e. non-child) 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 mdio-mux node). Fortunately, this was inadvertently balanced by a failure to drop the mdio-mux reference after lookup. While at it, also fix the related mdio-internal- and phy-node reference leaks. Fixes: 634db83 ("net: stmmac: dwmac-sun8i: Handle integrated/external MDIOs") Tested-by: Corentin Labbe <clabbe.montjoie@gmail.com> Cc: Andrew Lunn <andrew@lunn.ch> Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com> Cc: Alexandre Torgue <alexandre.torgue@st.com> Cc: Jose Abreu <joabreu@synopsys.com> Cc: David S. Miller <davem@davemloft.net> Signed-off-by: Johan Hovold <johan@kernel.org> Signed-off-by: Rob Herring <robh@kernel.org>
1 parent d397dbe commit ac63043

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,9 @@ static int get_ephy_nodes(struct stmmac_priv *priv)
714714
return -ENODEV;
715715
}
716716

717-
mdio_internal = of_find_compatible_node(mdio_mux, NULL,
717+
mdio_internal = of_get_compatible_child(mdio_mux,
718718
"allwinner,sun8i-h3-mdio-internal");
719+
of_node_put(mdio_mux);
719720
if (!mdio_internal) {
720721
dev_err(priv->device, "Cannot get internal_mdio node\n");
721722
return -ENODEV;
@@ -729,13 +730,20 @@ static int get_ephy_nodes(struct stmmac_priv *priv)
729730
gmac->rst_ephy = of_reset_control_get_exclusive(iphynode, NULL);
730731
if (IS_ERR(gmac->rst_ephy)) {
731732
ret = PTR_ERR(gmac->rst_ephy);
732-
if (ret == -EPROBE_DEFER)
733+
if (ret == -EPROBE_DEFER) {
734+
of_node_put(iphynode);
735+
of_node_put(mdio_internal);
733736
return ret;
737+
}
734738
continue;
735739
}
736740
dev_info(priv->device, "Found internal PHY node\n");
741+
of_node_put(iphynode);
742+
of_node_put(mdio_internal);
737743
return 0;
738744
}
745+
746+
of_node_put(mdio_internal);
739747
return -ENODEV;
740748
}
741749

0 commit comments

Comments
 (0)