diff mbox series

net: ethernet: mtk_eth_soc: fix memory leak in mtk_ppe_init()

Message ID 20221112233239.824389-1-nalanzeyu@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: ethernet: mtk_eth_soc: fix memory leak in mtk_ppe_init() | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers fail 1 blamed authors not CCed: davem@davemloft.net; 8 maintainers not CCed: pabeni@redhat.com davem@davemloft.net edumazet@google.com matthias.bgg@gmail.com kuba@kernel.org linux-arm-kernel@lists.infradead.org linux-mediatek@lists.infradead.org lorenzo@kernel.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 24 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Yan Cangang Nov. 12, 2022, 11:32 p.m. UTC
When dmam_alloc_coherent() or devm_kzalloc() failed, the rhashtable
    ppe->l2_flows isn't destroyed. Fix it.

Fixes: 33fc42de3327 ("net: ethernet: mtk_eth_soc: support creating mac address based offload entries")
Signed-off-by: Yan Cangang <nalanzeyu@gmail.com>
---
 drivers/net/ethernet/mediatek/mtk_ppe.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Leon Romanovsky Nov. 14, 2022, 7:59 a.m. UTC | #1
On Sun, Nov 13, 2022 at 07:32:39AM +0800, Yan Cangang wrote:
>     When dmam_alloc_coherent() or devm_kzalloc() failed, the rhashtable
>     ppe->l2_flows isn't destroyed. Fix it.
 ^^^^^
Please fix indentation in commit message.

> 
> Fixes: 33fc42de3327 ("net: ethernet: mtk_eth_soc: support creating mac address based offload entries")
> Signed-off-by: Yan Cangang <nalanzeyu@gmail.com>
> ---
>  drivers/net/ethernet/mediatek/mtk_ppe.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
> index 2d8ca99f2467..8da4c8be59fd 100644
> --- a/drivers/net/ethernet/mediatek/mtk_ppe.c
> +++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
> @@ -737,7 +737,7 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base,
>  				  MTK_PPE_ENTRIES * soc->foe_entry_size,
>  				  &ppe->foe_phys, GFP_KERNEL);
>  	if (!foe)
> -		return NULL;
> +		goto err_free_l2_flows;
>  
>  	ppe->foe_table = foe;
>  
> @@ -745,11 +745,15 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base,
>  			sizeof(*ppe->foe_flow);
>  	ppe->foe_flow = devm_kzalloc(dev, foe_flow_size, GFP_KERNEL);
>  	if (!ppe->foe_flow)
> -		return NULL;
> +		goto err_free_l2_flows;
>  
>  	mtk_ppe_debugfs_init(ppe, index);
>  
>  	return ppe;
> +
> +err_free_l2_flows:
> +	rhashtable_destroy(&ppe->l2_flows);

I expect the same change to be in mtk_mdio_cleanup() too.

Thanks


> +	return NULL;
>  }
>  
>  static void mtk_ppe_init_foe_table(struct mtk_ppe *ppe)
> -- 
> 2.30.2
>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
index 2d8ca99f2467..8da4c8be59fd 100644
--- a/drivers/net/ethernet/mediatek/mtk_ppe.c
+++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
@@ -737,7 +737,7 @@  struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base,
 				  MTK_PPE_ENTRIES * soc->foe_entry_size,
 				  &ppe->foe_phys, GFP_KERNEL);
 	if (!foe)
-		return NULL;
+		goto err_free_l2_flows;
 
 	ppe->foe_table = foe;
 
@@ -745,11 +745,15 @@  struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base,
 			sizeof(*ppe->foe_flow);
 	ppe->foe_flow = devm_kzalloc(dev, foe_flow_size, GFP_KERNEL);
 	if (!ppe->foe_flow)
-		return NULL;
+		goto err_free_l2_flows;
 
 	mtk_ppe_debugfs_init(ppe, index);
 
 	return ppe;
+
+err_free_l2_flows:
+	rhashtable_destroy(&ppe->l2_flows);
+	return NULL;
 }
 
 static void mtk_ppe_init_foe_table(struct mtk_ppe *ppe)