* [PATCH net-next v2] net: ethernet: mtk_eth_soc: add missing check for rhashtable_init
@ 2024-05-17 2:39 Chen Ni
2024-05-27 23:42 ` Jakub Kicinski
0 siblings, 1 reply; 2+ messages in thread
From: Chen Ni @ 2024-05-17 2:39 UTC (permalink / raw)
To: nbd, sean.wang, Mark-MC.Lee, lorenzo, davem, edumazet, kuba,
pabeni, matthias.bgg, angelogioacchino.delregno
Cc: netdev, linux-kernel, linux-arm-kernel, linux-mediatek, Chen Ni
Add check for the return value of rhashtable_init() and return the error
if it fails in order to catch the error.
Fixes: 33fc42de3327 ("net: ethernet: mtk_eth_soc: support creating mac address based offload entries")
Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
---
Changelog:
v1 -> v2:
1. Rewrite the error handling.
---
drivers/net/ethernet/mediatek/mtk_eth_soc.c | 2 +-
drivers/net/ethernet/mediatek/mtk_ppe.c | 5 ++++-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index cae46290a7ae..f9b8956a8726 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -4957,7 +4957,7 @@ static int mtk_probe(struct platform_device *pdev)
eth->ppe[i] = mtk_ppe_init(eth, eth->base + ppe_addr, i);
- if (!eth->ppe[i]) {
+ if (IS_ERR_OR_NULL(eth->ppe[i])) {
err = -ENOMEM;
goto err_deinit_ppe;
}
diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
index 0acee405a749..4895c6febaf8 100644
--- a/drivers/net/ethernet/mediatek/mtk_ppe.c
+++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
@@ -884,12 +884,15 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int index)
struct mtk_ppe *ppe;
u32 foe_flow_size;
void *foe;
+ int ret;
ppe = devm_kzalloc(dev, sizeof(*ppe), GFP_KERNEL);
if (!ppe)
return NULL;
- rhashtable_init(&ppe->l2_flows, &mtk_flow_l2_ht_params);
+ ret = rhashtable_init(&ppe->l2_flows, &mtk_flow_l2_ht_params);
+ if (ret)
+ return ERR_PTR(ret);
/* need to allocate a separate device, since it PPE DMA access is
* not coherent.
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next v2] net: ethernet: mtk_eth_soc: add missing check for rhashtable_init
2024-05-17 2:39 [PATCH net-next v2] net: ethernet: mtk_eth_soc: add missing check for rhashtable_init Chen Ni
@ 2024-05-27 23:42 ` Jakub Kicinski
0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2024-05-27 23:42 UTC (permalink / raw)
To: Chen Ni
Cc: nbd, sean.wang, Mark-MC.Lee, lorenzo, davem, edumazet, pabeni,
matthias.bgg, angelogioacchino.delregno, netdev, linux-kernel,
linux-arm-kernel, linux-mediatek
On Fri, 17 May 2024 10:39:22 +0800 Chen Ni wrote:
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index cae46290a7ae..f9b8956a8726 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -4957,7 +4957,7 @@ static int mtk_probe(struct platform_device *pdev)
>
> eth->ppe[i] = mtk_ppe_init(eth, eth->base + ppe_addr, i);
>
> - if (!eth->ppe[i]) {
> + if (IS_ERR_OR_NULL(eth->ppe[i])) {
> err = -ENOMEM;
You still discard the real error here.
> goto err_deinit_ppe;
> }
> diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
> index 0acee405a749..4895c6febaf8 100644
> --- a/drivers/net/ethernet/mediatek/mtk_ppe.c
> +++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
> @@ -884,12 +884,15 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int index)
> struct mtk_ppe *ppe;
> u32 foe_flow_size;
> void *foe;
> + int ret;
>
> ppe = devm_kzalloc(dev, sizeof(*ppe), GFP_KERNEL);
> if (!ppe)
> return NULL;
Please convert the return NULL in this function to
return ERR_PTR(-ENOMEM) and use the error code in mtk_probe()
> - rhashtable_init(&ppe->l2_flows, &mtk_flow_l2_ht_params);
> + ret = rhashtable_init(&ppe->l2_flows, &mtk_flow_l2_ht_params);
> + if (ret)
> + return ERR_PTR(ret);
Also there are two direct return NULLs without calling rhashtable_destroy()
later in this function. Please fix that in a separate patch.
> /* need to allocate a separate device, since it PPE DMA access is
> * not coherent.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-05-27 23:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-17 2:39 [PATCH net-next v2] net: ethernet: mtk_eth_soc: add missing check for rhashtable_init Chen Ni
2024-05-27 23:42 ` Jakub Kicinski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).