public inbox for linux-mips@vger.kernel.org
 help / color / mirror / Atom feed
From: Florian Fainelli <f.fainelli@gmail.com>
To: QintaoShen <unSimple1993@163.com>, "Rafał Miłecki" <rafal@milecki.pl>
Cc: bcm-kernel-feedback-list@broadcom.com,
	linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1] soc: bcm: Check for NULL return of devm_kzalloc()
Date: Thu, 24 Mar 2022 10:04:44 -0700	[thread overview]
Message-ID: <2a8afc70-c0d8-2b37-9d49-9a054a30ea4b@gmail.com> (raw)
In-Reply-To: <1648110940-4684-1-git-send-email-unSimple1993@163.com>

+Rafal,

On 3/24/22 01:35, QintaoShen wrote:
> As the potential failuer of allocation, devm_kzalloc() may return NULL.

s/failuer/failure/

> Then the 'pd->pmb' and the follow lines of code may bring null pointer dereference.
> 
> Therefore, it is better to check the return value of devm_kzalloc() to avoid this confusion.
> 
> Signed-off-by: QintaoShen <unSimple1993@163.com>

Fixes: 8bcac4011ebe ("soc: bcm: add PM driver for Broadcom's PMB")

> ---
>   drivers/soc/bcm/bcm63xx/bcm-pmb.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/soc/bcm/bcm63xx/bcm-pmb.c b/drivers/soc/bcm/bcm63xx/bcm-pmb.c
> index 7bbe46e..55bf389 100644
> --- a/drivers/soc/bcm/bcm63xx/bcm-pmb.c
> +++ b/drivers/soc/bcm/bcm63xx/bcm-pmb.c
> @@ -311,6 +311,8 @@ static int bcm_pmb_probe(struct platform_device *pdev)
>   
>   	for (e = table; e->name; e++) {
>   		struct bcm_pmb_pm_domain *pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
> +		if (!pd)
> +			return -ENOMEM;

I am of two minds as to what the appropriate behavior could be here, we 
could equally use an:

		if (!pd)
			continue;

or do what you are doing.

>   
>   		pd->pmb = pmb;
>   		pd->data = e;


-- 
Florian

  reply	other threads:[~2022-03-24 17:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-24  8:35 [PATCH v1] soc: bcm: Check for NULL return of devm_kzalloc() QintaoShen
2022-03-24 17:04 ` Florian Fainelli [this message]
2022-03-25  9:02 ` Sergey Shtylyov
2022-03-28  4:13   ` QintaoShen
2022-04-19 18:33 ` Florian Fainelli

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=2a8afc70-c0d8-2b37-9d49-9a054a30ea4b@gmail.com \
    --to=f.fainelli@gmail.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=rafal@milecki.pl \
    --cc=unSimple1993@163.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