Skip to content

Commit 0cb2c50

Browse files
joehattoriPaolo Abeni
authored andcommitted
net: ethernet: bgmac-platform: fix an OF node reference leak
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: 1676aba ("net: ethernet: bgmac: device tree phy enablement") Signed-off-by: Joe Hattori <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 90d130a commit 0cb2c50

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/net/ethernet/broadcom/bgmac-platform.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ static int platform_phy_connect(struct bgmac *bgmac)
171171
static int bgmac_probe(struct platform_device *pdev)
172172
{
173173
struct device_node *np = pdev->dev.of_node;
174+
struct device_node *phy_node;
174175
struct bgmac *bgmac;
175176
struct resource *regs;
176177
int ret;
@@ -236,7 +237,9 @@ static int bgmac_probe(struct platform_device *pdev)
236237
bgmac->cco_ctl_maskset = platform_bgmac_cco_ctl_maskset;
237238
bgmac->get_bus_clock = platform_bgmac_get_bus_clock;
238239
bgmac->cmn_maskset32 = platform_bgmac_cmn_maskset32;
239-
if (of_parse_phandle(np, "phy-handle", 0)) {
240+
phy_node = of_parse_phandle(np, "phy-handle", 0);
241+
if (phy_node) {
242+
of_node_put(phy_node);
240243
bgmac->phy_connect = platform_phy_connect;
241244
} else {
242245
bgmac->phy_connect = bgmac_phy_connect_direct;

0 commit comments

Comments
 (0)