diff mbox series

net: ethernet: ti: am65-cpsw: fix NULL deref check in am65_cpsw_nuss_probe

Message ID 20241025091139.230117-1-hanchunchao@inspur.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: ethernet: ti: am65-cpsw: fix NULL deref check in am65_cpsw_nuss_probe | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5 this patch: 5
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 3 this patch: 3
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
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: 3 this patch: 3
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 9 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Charles Han Oct. 25, 2024, 9:11 a.m. UTC
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 <hanchunchao@inspur.com>
---
 drivers/net/ethernet/ti/am65-cpsw-nuss.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Simon Horman Oct. 26, 2024, 12:43 p.m. UTC | #1
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 <hanchunchao@inspur.com>

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] ...

> ---
>  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;
diff mbox series

Patch

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;
+
 	ret = am65_cpsw_init_cpts(common);
 	if (ret)
 		goto err_of_clear;