]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: ethernet: bgmac-platform: fix an OF node reference leak
authorJoe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
Sat, 14 Dec 2024 01:49:12 +0000 (10:49 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 9 Jan 2025 12:24:52 +0000 (13:24 +0100)
[ Upstream commit 0cb2c504d79e7caa3abade3f466750c82ad26f01 ]

The OF node obtained by of_parse_phandle() is not freed. Call
of_node_put() to balance the refcount.

This bug was found by an experimental static analysis tool that I am
developing.

Fixes: 1676aba5ef7e ("net: ethernet: bgmac: device tree phy enablement")
Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20241214014912.2810315-1-joe@pf.is.s.u-tokyo.ac.jp
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/broadcom/bgmac-platform.c

index f37f1c58f3689308082df39fc30ad41dbb4920d9..c2e0bc1326fe159e799dd20ae30a88761cb64dd3 100644 (file)
@@ -171,6 +171,7 @@ static int platform_phy_connect(struct bgmac *bgmac)
 static int bgmac_probe(struct platform_device *pdev)
 {
        struct device_node *np = pdev->dev.of_node;
+       struct device_node *phy_node;
        struct bgmac *bgmac;
        struct resource *regs;
        const u8 *mac_addr;
@@ -232,7 +233,9 @@ static int bgmac_probe(struct platform_device *pdev)
        bgmac->cco_ctl_maskset = platform_bgmac_cco_ctl_maskset;
        bgmac->get_bus_clock = platform_bgmac_get_bus_clock;
        bgmac->cmn_maskset32 = platform_bgmac_cmn_maskset32;
-       if (of_parse_phandle(np, "phy-handle", 0)) {
+       phy_node = of_parse_phandle(np, "phy-handle", 0);
+       if (phy_node) {
+               of_node_put(phy_node);
                bgmac->phy_connect = platform_phy_connect;
        } else {
                bgmac->phy_connect = bgmac_phy_connect_direct;