public inbox for linux-mips@vger.kernel.org
 help / color / mirror / Atom feed
From: QintaoShen <unSimple1993@163.com>
To: tsbogend@alpha.franken.de
Cc: linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org,
	ralf@linux-mips.org, QintaoShen <unSimple1993@163.com>
Subject: [PATCH v1] MIPS: ip22-gio: Add check for the return value of kzalloc()
Date: Mon, 28 Mar 2022 16:04:14 +0800	[thread overview]
Message-ID: <1648454654-27200-1-git-send-email-unSimple1993@163.com> (raw)

Since the memory allocation function kzalloc() may return a NULL pointer,
the use of 'gio_dev' may lead to NULL pointer dereference.

So it is better to check the return value of kzalloc().

Signed-off-by: QintaoShen <unSimple1993@163.com>
---
 arch/mips/sgi-ip22/ip22-gio.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/mips/sgi-ip22/ip22-gio.c b/arch/mips/sgi-ip22/ip22-gio.c
index dfc52f6..df7ca21 100644
--- a/arch/mips/sgi-ip22/ip22-gio.c
+++ b/arch/mips/sgi-ip22/ip22-gio.c
@@ -363,7 +363,11 @@ static void ip22_check_gio(int slotno, unsigned long addr, int irq)
 		printk(KERN_INFO "GIO: slot %d : %s (id %x)\n",
 		       slotno, name, id);
 		gio_dev = kzalloc(sizeof *gio_dev, GFP_KERNEL);
-		gio_dev->name = name;
+		
+        if (!gio_dev)
+            return ;
+
+        gio_dev->name = name;
 		gio_dev->slotno = slotno;
 		gio_dev->id.id = id;
 		gio_dev->resource.start = addr;
-- 
2.7.4


             reply	other threads:[~2022-03-28  8:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-28  8:04 QintaoShen [this message]
2022-03-29  8:35 ` [PATCH v1] MIPS: ip22-gio: Add check for the return value of kzalloc() Sergey Shtylyov
     [not found]   ` <16aa9238.4bf6.17fd8fe37ad.Coremail.unsimple1993@163.com>
2022-04-01  9:09     ` Sergey Shtylyov

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=1648454654-27200-1-git-send-email-unSimple1993@163.com \
    --to=unsimple1993@163.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=ralf@linux-mips.org \
    --cc=tsbogend@alpha.franken.de \
    /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