Re: [PATCH] net: ethernet: ti: am65-cpsw: fix NULL deref check in am65_cpsw_nuss_probe
From: Simon Horman <horms@kernel.org>
Date: 2024-10-26 12:43:27
Also in:
lkml
On Fri, Oct 25, 2024 at 05:11:39PM +0800, Charles Han wrote:
In am65_cpsw_nuss_probe() devm_kzalloc() may return NULL but this
returned value is not checked.
Fixes: 1af3cb3702d0 ("net: ethernet: ti: am65-cpsw: Fix hardware switch mode on suspend/resume")
Signed-off-by: Charles Han <redacted>Hi Charles, As this is a fix for Networking code it should be explicitly targeted at the net tree like this: Subject: [PATCH net v2] ...
quoted hunk ↗ jump to hunk
--- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 3 +++ 1 file changed, 3 insertions(+)diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c index 6201a09fa5f0..7af7542093e8 100644 --- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c +++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c@@ -3528,6 +3528,9 @@ static int am65_cpsw_nuss_probe(struct platform_device *pdev) common->ale_context = devm_kzalloc(dev, ale_entries * ALE_ENTRY_WORDS * sizeof(u32), GFP_KERNEL); + if (!common->ale_context) + return -ENOMEM; +
While I agree this error should be checked, I don't think this error
handling is correct and will lead to leaked resources. Looking
over this function I think you want (completely untested!):
if (!common->ale_context) {
ret = -ENOMEM;
goto err_of_clear;
}
ret = am65_cpsw_init_cpts(common); if (ret) goto err_of_clear;
-- pw-bot: changes-requested