Skip to content

Commit 9919a36

Browse files
tasksetdavem330
authored andcommitted
net: dsa: fix a leaked reference by adding missing of_node_put
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]>
1 parent 71828b2 commit 9919a36

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

net/dsa/dsa2.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,8 @@ static int dsa_switch_parse_ports_of(struct dsa_switch *ds,
612612
{
613613
struct device_node *ports, *port;
614614
struct dsa_port *dp;
615+
int err = 0;
615616
u32 reg;
616-
int err;
617617

618618
ports = of_get_child_by_name(dn, "ports");
619619
if (!ports) {
@@ -624,19 +624,23 @@ static int dsa_switch_parse_ports_of(struct dsa_switch *ds,
624624
for_each_available_child_of_node(ports, port) {
625625
err = of_property_read_u32(port, "reg", &reg);
626626
if (err)
627-
return err;
627+
goto out_put_node;
628628

629-
if (reg >= ds->num_ports)
630-
return -EINVAL;
629+
if (reg >= ds->num_ports) {
630+
err = -EINVAL;
631+
goto out_put_node;
632+
}
631633

632634
dp = &ds->ports[reg];
633635

634636
err = dsa_port_parse_of(dp, port);
635637
if (err)
636-
return err;
638+
goto out_put_node;
637639
}
638640

639-
return 0;
641+
out_put_node:
642+
of_node_put(ports);
643+
return err;
640644
}
641645

642646
static int dsa_switch_parse_member_of(struct dsa_switch *ds,

net/dsa/port.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ static struct phy_device *dsa_port_get_phy_device(struct dsa_port *dp)
292292
return ERR_PTR(-EPROBE_DEFER);
293293
}
294294

295+
of_node_put(phy_dn);
295296
return phydev;
296297
}
297298

0 commit comments

Comments
 (0)