netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Charles Han <hanchunchao@inspur.com>
Cc: rogerq@kernel.org, andrew+netdev@lunn.ch, davem@davemloft.net,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	jpanis@baylibre.com, dan.carpenter@linaro.org,
	grygorii.strashko@ti.com, u.kleine-koenig@baylibre.com,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net: ethernet: ti: am65-cpsw: fix NULL deref check in am65_cpsw_nuss_probe
Date: Sat, 26 Oct 2024 13:43:22 +0100	[thread overview]
Message-ID: <20241026124322.GC1507976@kernel.org> (raw)
In-Reply-To: <20241025091139.230117-1-hanchunchao@inspur.com>

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;

-- 
pw-bot: changes-requested

      reply	other threads:[~2024-10-26 12:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-25  9:11 [PATCH] net: ethernet: ti: am65-cpsw: fix NULL deref check in am65_cpsw_nuss_probe Charles Han
2024-10-26 12:43 ` Simon Horman [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241026124322.GC1507976@kernel.org \
    --to=horms@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=dan.carpenter@linaro.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=grygorii.strashko@ti.com \
    --cc=hanchunchao@inspur.com \
    --cc=jpanis@baylibre.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rogerq@kernel.org \
    --cc=u.kleine-koenig@baylibre.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).