public inbox for linux-mips@vger.kernel.org
 help / color / mirror / Atom feed
From: QintaoShen <unSimple1993@163.com>
To: f.fainelli@gmail.com
Cc: bcm-kernel-feedback-list@broadcom.com,
	linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org,
	QintaoShen <unSimple1993@163.com>
Subject: [PATCH v1] soc: bcm: Check for NULL return of devm_kzalloc()
Date: Thu, 24 Mar 2022 16:35:40 +0800	[thread overview]
Message-ID: <1648110940-4684-1-git-send-email-unSimple1993@163.com> (raw)

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.

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);
+		if (!pd)
+			return -ENOMEM;
 
 		pd->pmb = pmb;
 		pd->data = e;
-- 
2.7.4


             reply	other threads:[~2022-03-24  8:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-24  8:35 QintaoShen [this message]
2022-03-24 17:04 ` [PATCH v1] soc: bcm: Check for NULL return of devm_kzalloc() Florian Fainelli
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=1648110940-4684-1-git-send-email-unSimple1993@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 \
    /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