Skip to content

Commit

Permalink
net: dsa: fix a leaked reference by adding missing of_node_put
Browse files Browse the repository at this point in the history
The call to of_parse_phandle returns a node pointer with refcount
incremented thus it must be explicitly decremented after the last
usage.

Detected by coccinelle with the following warnings:
./net/dsa/port.c:294:1-7: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 284, but without a corresponding object release within this function.
./net/dsa/dsa2.c:627:3-9: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 618, but without a corresponding object release within this function.
./net/dsa/dsa2.c:630:3-9: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 618, but without a corresponding object release within this function.
./net/dsa/dsa2.c:636:3-9: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 618, but without a corresponding object release within this function.
./net/dsa/dsa2.c:639:1-7: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 618, but without a corresponding object release within this function.

Signed-off-by: Wen Yang <[email protected]>
Reviewed-by: Vivien Didelot <[email protected]>
Cc: Andrew Lunn <[email protected]>
Cc: Vivien Didelot <[email protected]>
Cc: Florian Fainelli <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Vivien Didelot <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
taskset authored and davem330 committed Feb 25, 2019
1 parent 71828b2 commit 9919a36
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
16 changes: 10 additions & 6 deletions net/dsa/dsa2.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,8 @@ static int dsa_switch_parse_ports_of(struct dsa_switch *ds,
{
struct device_node *ports, *port;
struct dsa_port *dp;
int err = 0;
u32 reg;
int err;

ports = of_get_child_by_name(dn, "ports");
if (!ports) {
Expand All @@ -624,19 +624,23 @@ static int dsa_switch_parse_ports_of(struct dsa_switch *ds,
for_each_available_child_of_node(ports, port) {
err = of_property_read_u32(port, "reg", &reg);
if (err)
return err;
goto out_put_node;

if (reg >= ds->num_ports)
return -EINVAL;
if (reg >= ds->num_ports) {
err = -EINVAL;
goto out_put_node;
}

dp = &ds->ports[reg];

err = dsa_port_parse_of(dp, port);
if (err)
return err;
goto out_put_node;
}

return 0;
out_put_node:
of_node_put(ports);
return err;
}

static int dsa_switch_parse_member_of(struct dsa_switch *ds,
Expand Down
1 change: 1 addition & 0 deletions net/dsa/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ static struct phy_device *dsa_port_get_phy_device(struct dsa_port *dp)
return ERR_PTR(-EPROBE_DEFER);
}

of_node_put(phy_dn);
return phydev;
}

Expand Down

0 comments on commit 9919a36

Please sign in to comment.