Skip to content

Commit 572af9f

Browse files
joehattoriPaolo Abeni
authored andcommitted
net: mdiobus: fix an OF node reference leak
fwnode_find_mii_timestamper() calls of_parse_phandle_with_fixed_args() but does not decrement the refcount of the obtained OF node. Add an of_node_put() call before returning from the function. This bug was detected by an experimental static analysis tool that I am developing. Fixes: bc1bee3 ("net: mdiobus: Introduce fwnode_mdiobus_register_phy()") Signed-off-by: Joe Hattori <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent b4adc04 commit 572af9f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

drivers/net/mdio/fwnode_mdio.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ fwnode_find_pse_control(struct fwnode_handle *fwnode)
4040
static struct mii_timestamper *
4141
fwnode_find_mii_timestamper(struct fwnode_handle *fwnode)
4242
{
43+
struct mii_timestamper *mii_ts;
4344
struct of_phandle_args arg;
4445
int err;
4546

@@ -53,10 +54,16 @@ fwnode_find_mii_timestamper(struct fwnode_handle *fwnode)
5354
else if (err)
5455
return ERR_PTR(err);
5556

56-
if (arg.args_count != 1)
57-
return ERR_PTR(-EINVAL);
57+
if (arg.args_count != 1) {
58+
mii_ts = ERR_PTR(-EINVAL);
59+
goto put_node;
60+
}
61+
62+
mii_ts = register_mii_timestamper(arg.np, arg.args[0]);
5863

59-
return register_mii_timestamper(arg.np, arg.args[0]);
64+
put_node:
65+
of_node_put(arg.np);
66+
return mii_ts;
6067
}
6168

6269
int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio,

0 commit comments

Comments
 (0)