linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: QintaoShen <unSimple1993@163.com>
To: Sergey Shtylyov <s.shtylyov@omp.ru>
Cc: bcm-kernel-feedback-list@broadcom.com, f.fainelli@gmail.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: Mon, 28 Mar 2022 12:13:40 +0800	[thread overview]
Message-ID: <37a63518-5d68-fddf-a10b-1aad2c2302c1@163.com> (raw)
In-Reply-To: <0f5e77e9-3c2c-396d-636b-1b7153007fe5@omp.ru>

OK. Here is the new version.

Signed-off-by: QintaoShen <unSimple1993@163.com>
---
  drivers/soc/bcm/bcm63xx/bcm-pmb.c | 3 +++
  1 file changed, 3 insertions(+)

diff --git a/drivers/soc/bcm/bcm63xx/bcm-pmb.c 
b/drivers/soc/bcm/bcm63xx/bcm-pmb.c
index 7bbe46e..cc20ffb 100644
--- a/drivers/soc/bcm/bcm63xx/bcm-pmb.c
+++ b/drivers/soc/bcm/bcm63xx/bcm-pmb.c
@@ -312,6 +312,9 @@ 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;
+
          pd->pmb = pmb;
          pd->data = e;
          pd->genpd.name = e->name;
-- 
2.7.4

在 2022/3/25 下午5:02, Sergey Shtylyov 写道:
> Hello!
>
>     s/return/result/ in the subject.
>
> On 3/24/22 11:35 AM, QintaoShen wrote:
>
>> As the potential failuer of allocation, devm_kzalloc() may return NULL.
>> Then the 'pd->pmb' and the follow lines of code may bring null pointer dereference.
>     Following.
>
>> Therefore, it is better to check the return value of devm_kzalloc() to avoid this confusion.
>>
>> Signed-off-by: QintaoShen <unSimple1993@163.com>
>> ---
>>   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);
>     Please keep an empty line after declaration.
>
>> +		if (!pd)
>> +			return -ENOMEM;
>>   
>>   		pd->pmb = pmb;
>>   		pd->data = e;
> MBR, Sergey


  reply	other threads:[~2022-03-28  4:14 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
2022-03-25  9:02 ` Sergey Shtylyov
2022-03-28  4:13   ` QintaoShen [this message]
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=37a63518-5d68-fddf-a10b-1aad2c2302c1@163.com \
    --to=unsimple1993@163.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=f.fainelli@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=s.shtylyov@omp.ru \
    /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).