Skip to content

Commit a887b59

Browse files
committed
Merge branch 'mtk_eth_wed-leak-fixes'
Yang Yingliang says: ==================== net: ethernet: mtk_eth_wed: fixe some leaks I found some leaks in mtk_eth_soc.c/mtk_wed.c. patch#1 - I found mtk_wed_exit() is never called, I think mtk_wed_exit() need be called in error path or module remove function to free the memory allocated in mtk_wed_add_hw(). patch#2 - The device is not put in error path in mtk_wed_add_hw(). patch#3 - The device_node pointer returned by of_parse_phandle() with refcount incremented, it should be decreased when it done. This patchset was just compiled tested because I don't have any HW on which to do the actual tests. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 2d1f274 + e0bb465 commit a887b59

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

drivers/net/ethernet/mediatek/mtk_eth_soc.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4060,19 +4060,23 @@ static int mtk_probe(struct platform_device *pdev)
40604060
eth->irq[i] = platform_get_irq(pdev, i);
40614061
if (eth->irq[i] < 0) {
40624062
dev_err(&pdev->dev, "no IRQ%d resource found\n", i);
4063-
return -ENXIO;
4063+
err = -ENXIO;
4064+
goto err_wed_exit;
40644065
}
40654066
}
40664067
for (i = 0; i < ARRAY_SIZE(eth->clks); i++) {
40674068
eth->clks[i] = devm_clk_get(eth->dev,
40684069
mtk_clks_source_name[i]);
40694070
if (IS_ERR(eth->clks[i])) {
4070-
if (PTR_ERR(eth->clks[i]) == -EPROBE_DEFER)
4071-
return -EPROBE_DEFER;
4071+
if (PTR_ERR(eth->clks[i]) == -EPROBE_DEFER) {
4072+
err = -EPROBE_DEFER;
4073+
goto err_wed_exit;
4074+
}
40724075
if (eth->soc->required_clks & BIT(i)) {
40734076
dev_err(&pdev->dev, "clock %s not found\n",
40744077
mtk_clks_source_name[i]);
4075-
return -EINVAL;
4078+
err = -EINVAL;
4079+
goto err_wed_exit;
40764080
}
40774081
eth->clks[i] = NULL;
40784082
}
@@ -4083,7 +4087,7 @@ static int mtk_probe(struct platform_device *pdev)
40834087

40844088
err = mtk_hw_init(eth);
40854089
if (err)
4086-
return err;
4090+
goto err_wed_exit;
40874091

40884092
eth->hwlro = MTK_HAS_CAPS(eth->soc->caps, MTK_HWLRO);
40894093

@@ -4179,6 +4183,8 @@ static int mtk_probe(struct platform_device *pdev)
41794183
mtk_free_dev(eth);
41804184
err_deinit_hw:
41814185
mtk_hw_deinit(eth);
4186+
err_wed_exit:
4187+
mtk_wed_exit();
41824188

41834189
return err;
41844190
}
@@ -4198,6 +4204,7 @@ static int mtk_remove(struct platform_device *pdev)
41984204
phylink_disconnect_phy(mac->phylink);
41994205
}
42004206

4207+
mtk_wed_exit();
42014208
mtk_hw_deinit(eth);
42024209

42034210
netif_napi_del(&eth->tx_napi);

drivers/net/ethernet/mediatek/mtk_wed.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,16 +1072,16 @@ void mtk_wed_add_hw(struct device_node *np, struct mtk_eth *eth,
10721072

10731073
pdev = of_find_device_by_node(np);
10741074
if (!pdev)
1075-
return;
1075+
goto err_of_node_put;
10761076

10771077
get_device(&pdev->dev);
10781078
irq = platform_get_irq(pdev, 0);
10791079
if (irq < 0)
1080-
return;
1080+
goto err_put_device;
10811081

10821082
regs = syscon_regmap_lookup_by_phandle(np, NULL);
10831083
if (IS_ERR(regs))
1084-
return;
1084+
goto err_put_device;
10851085

10861086
rcu_assign_pointer(mtk_soc_wed_ops, &wed_ops);
10871087

@@ -1124,8 +1124,16 @@ void mtk_wed_add_hw(struct device_node *np, struct mtk_eth *eth,
11241124

11251125
hw_list[index] = hw;
11261126

1127+
mutex_unlock(&hw_lock);
1128+
1129+
return;
1130+
11271131
unlock:
11281132
mutex_unlock(&hw_lock);
1133+
err_put_device:
1134+
put_device(&pdev->dev);
1135+
err_of_node_put:
1136+
of_node_put(np);
11291137
}
11301138

11311139
void mtk_wed_exit(void)
@@ -1146,6 +1154,7 @@ void mtk_wed_exit(void)
11461154
hw_list[i] = NULL;
11471155
debugfs_remove(hw->debugfs_dir);
11481156
put_device(hw->dev);
1157+
of_node_put(hw->node);
11491158
kfree(hw);
11501159
}
11511160
}

0 commit comments

Comments
 (0)