diff options
author | Wen Yang <wen.yang99@zte.com.cn> | 2019-02-25 02:22:19 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2019-02-25 12:34:52 -0500 |
commit | 9919a363a5cb57c2b64c4803b4d2dd45e90bf230 (patch) | |
tree | 27b0c4d86bcadf5e365ab70367abb1b3cde2f3e0 /net/dsa/dsa2.c | |
parent | 71828b2240692cec0e68b8d867bc00e1745e7fae (diff) |
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 <wen.yang99@zte.com.cn>
Reviewed-by: Vivien Didelot <vivien.didelot@gmail.com>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Vivien Didelot <vivien.didelot@gmail.com>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Vivien Didelot <vivien.didelot@gmail.com>
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/dsa/dsa2.c')
-rw-r--r-- | net/dsa/dsa2.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index a1917025e155..410f19148106 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c | |||
@@ -612,8 +612,8 @@ static int dsa_switch_parse_ports_of(struct dsa_switch *ds, | |||
612 | { | 612 | { |
613 | struct device_node *ports, *port; | 613 | struct device_node *ports, *port; |
614 | struct dsa_port *dp; | 614 | struct dsa_port *dp; |
615 | int err = 0; | ||
615 | u32 reg; | 616 | u32 reg; |
616 | int err; | ||
617 | 617 | ||
618 | ports = of_get_child_by_name(dn, "ports"); | 618 | ports = of_get_child_by_name(dn, "ports"); |
619 | if (!ports) { | 619 | if (!ports) { |
@@ -624,19 +624,23 @@ static int dsa_switch_parse_ports_of(struct dsa_switch *ds, | |||
624 | for_each_available_child_of_node(ports, port) { | 624 | for_each_available_child_of_node(ports, port) { |
625 | err = of_property_read_u32(port, "reg", ®); | 625 | err = of_property_read_u32(port, "reg", ®); |
626 | if (err) | 626 | if (err) |
627 | return err; | 627 | goto out_put_node; |
628 | 628 | ||
629 | if (reg >= ds->num_ports) | 629 | if (reg >= ds->num_ports) { |
630 | return -EINVAL; | 630 | err = -EINVAL; |
631 | goto out_put_node; | ||
632 | } | ||
631 | 633 | ||
632 | dp = &ds->ports[reg]; | 634 | dp = &ds->ports[reg]; |
633 | 635 | ||
634 | err = dsa_port_parse_of(dp, port); | 636 | err = dsa_port_parse_of(dp, port); |
635 | if (err) | 637 | if (err) |
636 | return err; | 638 | goto out_put_node; |
637 | } | 639 | } |
638 | 640 | ||
639 | return 0; | 641 | out_put_node: |
642 | of_node_put(ports); | ||
643 | return err; | ||
640 | } | 644 | } |
641 | 645 | ||
642 | static int dsa_switch_parse_member_of(struct dsa_switch *ds, | 646 | static int dsa_switch_parse_member_of(struct dsa_switch *ds, |