]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
net: gianfar: Add of_node_put() before goto statement
authorSumera Priyadarsini <sylphrenadin@gmail.com>
Tue, 18 Aug 2020 18:52:41 +0000 (00:22 +0530)
committerKhalid Elmously <khalid.elmously@canonical.com>
Wed, 16 Sep 2020 09:15:01 +0000 (05:15 -0400)
BugLink: https://bugs.launchpad.net/bugs/1895174
[ Upstream commit 989e4da042ca4a56bbaca9223d1a93639ad11e17 ]

Every iteration of for_each_available_child_of_node() decrements
reference count of the previous node, however when control
is transferred from the middle of the loop, as in the case of
a return or break or goto, there is no decrement thus ultimately
resulting in a memory leak.

Fix a potential memory leak in gianfar.c by inserting of_node_put()
before the goto statement.

Issue found with Coccinelle.

Signed-off-by: Sumera Priyadarsini <sylphrenadin@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
drivers/net/ethernet/freescale/gianfar.c

index 2580bcd8502531639acfdbc440ef32dc2f68e831..3978d82c959898d90c9e2561c7499ad8bdab5e48 100644 (file)
@@ -751,8 +751,10 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev)
                                continue;
 
                        err = gfar_parse_group(child, priv, model);
-                       if (err)
+                       if (err) {
+                               of_node_put(child);
                                goto err_grp_init;
+                       }
                }
        } else { /* SQ_SG_MODE */
                err = gfar_parse_group(np, priv, model);