net: ethernet: mtk_ppe: Fix rhashtable leak in mtk_ppe_init error paths
Subsystems (4)
PATCH 1/1 net: ethernet: mtk_ppe: Fix rhashtable leak in mtk_ppe_init error paths
In mtk_ppe_init(), when accounting is enabled, the error paths for dmam_alloc_coherent(mib) and devm_kzalloc(acct) failures return NULL directly, bypassing the err_free_l2_flows label that destroys the rhashtable initialized earlier.
While this leak only occurs during probe (not runtime) and the leaked memory is minimal (an empty rhash table), fixing it ensures proper error path cleanup consistency.
Fix by changing the two return NULL statements to goto err_free_l2_flows.
--- drivers/net/ethernet/mediatek/mtk_ppe.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/mediatek/mtk_ppe.c +2 -2
@@ -918,7 +918,7 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int index) mib =dmam_alloc_coherent (ppe->dev,MTK_PPE_ENTRIES *sizeof (*mib), &ppe->mib_phys,GFP_KERNEL );if (!mib) -return NULL ; + goto err_free_l2_flows; ppe->mib_table = mib;
@@ -926,7 +926,7 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int index) GFP_KERNEL);if (!acct) -return NULL ; + goto err_free_l2_flows; ppe->acct_table = acct; }
Signature · 1 line
2.51.0
Quoted 5 lines
In
mtk_ppe_init(), when accounting is enabled, the error paths fordmam_alloc_coherent(mib)anddevm_kzalloc(acct)failures return NULL directly, bypassing theerr_free_l2_flowslabel that destroys the rhashtable initialized earlier.
Quoted 8 lines
While this leak only occurs during probe (not runtime) and the leaked memory is minimal (an empty rhash table), fixing it ensures proper error path cleanup consistency.
Fix by changing the two return NULL statements to goto
err_free_l2_flows.Fixes 603ea5e7ffa7 ("net: ethernet: mtk_eth_soc: fix memory leak in error path")Signed-off-by Wayen Yan <[email protected]>
Quoted 30 lines
--- drivers/net/ethernet/mediatek/mtk_ppe.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/ethernet/mediatek/mtk_ppe.c +2
-2@@ -918,7 +918,7 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int index) mib =dmam_alloc_coherent (ppe->dev,MTK_PPE_ENTRIES *sizeof (*mib), &ppe->mib_phys,GFP_KERNEL );if (!mib) -return NULL ; + goto err_free_l2_flows; ppe->mib_table = mib;@@ -926,7 +926,7 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int index) GFP_KERNEL);if (!acct) -return NULL ; + goto err_free_l2_flows; ppe->acct_table = acct; }Signature · 1 line
2.51.0
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Wed, 17 Jun 2026 13:48:13 +0800 you wrote:
In
mtk_ppe_init(), when accounting is enabled, the error paths fordmam_alloc_coherent(mib)anddevm_kzalloc(acct)failures return NULL directly, bypassing theerr_free_l2_flowslabel that destroys the rhashtable initialized earlier.While this leak only occurs during probe (not runtime) and the leaked memory is minimal (an empty rhash table), fixing it ensures proper error path cleanup consistency.
[...]
Here is the summary with links:
- [net] net: ethernet: mtk_ppe: Fix rhashtable leak in mtk_ppe_init error paths
https://git.kernel.org/netdev/net/c/41782770be56
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html