Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: dsa: lantiq_gswip: Fix refcount leak in gswip_gphy_fw_list

Every iteration of for_each_available_child_of_node() decrements
the reference count of the previous node.
when breaking early from a for_each_available_child_of_node() loop,
we need to explicitly call of_node_put() on the gphy_fw_np.
Add missing of_node_put() to avoid refcount leak.

Fixes: 14fceff4771e ("net: dsa: Add Lantiq / Intel DSA driver for vrx200")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
Link: https://lore.kernel.org/r/20220605072335.11257-1-linmq006@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Miaoqian Lin and committed by
Jakub Kicinski
0737e018 91ffb089

+3 -1
+3 -1
drivers/net/dsa/lantiq_gswip.c
··· 2070 2070 for_each_available_child_of_node(gphy_fw_list_np, gphy_fw_np) { 2071 2071 err = gswip_gphy_fw_probe(priv, &priv->gphy_fw[i], 2072 2072 gphy_fw_np, i); 2073 - if (err) 2073 + if (err) { 2074 + of_node_put(gphy_fw_np); 2074 2075 goto remove_gphy; 2076 + } 2075 2077 i++; 2076 2078 } 2077 2079