phy: renesas: rcar-gen2: Fix memory leak at error paths [Linux 4.4.187]

This Linux kernel change "phy: renesas: rcar-gen2: Fix memory leak at error paths" is included in the Linux 4.4.187 release. This change is authored by Yoshihiro Shimoda <yoshihiro.shimoda.uh [at]> on Tue May 28 14:04:02 2019 +0900. The commit for this change in Linux stable tree is 718514c (patch) which is from upstream commit d4a36e8. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream d4a36e8.

phy: renesas: rcar-gen2: Fix memory leak at error paths

[ Upstream commit d4a36e82924d3305a17ac987a510f3902df5a4b2 ]

This patch fixes memory leak at error paths of the probe function.
In for_each_child_of_node, if the loop returns, the driver should
call of_put_node() before returns.

Reported-by: Julia Lawall <>
Fixes: 1233f59f745b237 ("phy: Renesas R-Car Gen2 PHY driver")
Signed-off-by: Yoshihiro Shimoda <>
Reviewed-by: Geert Uytterhoeven <>
Signed-off-by: Kishon Vijay Abraham I <>
Signed-off-by: Sasha Levin <>

There are 2 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/phy/phy-rcar-gen2.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/phy/phy-rcar-gen2.c b/drivers/phy/phy-rcar-gen2.c
index c7a0599..99d2b73 100644
--- a/drivers/phy/phy-rcar-gen2.c
+++ b/drivers/phy/phy-rcar-gen2.c
@@ -287,6 +287,7 @@ static int rcar_gen2_phy_probe(struct platform_device *pdev)
        error = of_property_read_u32(np, "reg", &channel_num);
        if (error || channel_num > 2) {
            dev_err(dev, "Invalid \"reg\" property\n");
+           of_node_put(np);
            return error;
        channel->select_mask = select_mask[channel_num];
@@ -302,6 +303,7 @@ static int rcar_gen2_phy_probe(struct platform_device *pdev)
            if (IS_ERR(phy->phy)) {
                dev_err(dev, "Failed to create PHY\n");
+               of_node_put(np);
                return PTR_ERR(phy->phy);
            phy_set_drvdata(phy->phy, phy);

Leave a Reply

Your email address will not be published. Required fields are marked *