Skip to contentSkip to conversation

MIPS: ip22-gio: Add check for the return value of kzalloc()

PATCH In review QintaoShen 2 participants 3 messages Mar 28, 2022 – Apr 1, 2022 1 message not in the archive MIPS

lore
Share & tools
lore

QintaoShen

author
#0 lore raw

PATCH 1/1 MIPS: ip22-gio: Add check for the return value of kzalloc()

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().

---
 arch/mips/sgi-ip22/ip22-gio.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/mips/sgi-ip22/ip22-gio.c +5 -1
index dfc52f6..df7ca21 100644
@@ -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;
Signature · 1 line
2.7.4
#1 lore raw

Hello!

Quoted 15 lines · QintaoShen

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().

---
 arch/mips/sgi-ip22/ip22-gio.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/mips/sgi-ip22/ip22-gio.c +0 -0
index dfc52f6..df7ca21 100644

arch/mips/sgi-ip22/ip22-gio.c static void ip22_check_gio(int slotno, unsigned long addr, int irq) · line 367

Quoted 6 lines
arch/mips/sgi-ip22/ip22-gio.c +2 -1
@@ -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)

Indented too little. And indent with tabs please, not spaces.

arch/mips/sgi-ip22/ip22-gio.c static void ip22_check_gio(int slotno, unsigned long addr, int irq) · line 368

Quoted 1 line
arch/mips/sgi-ip22/ip22-gio.c +1 -0
+            return ;

No need for space before ';'.

[...]

MBR, Sergey

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 1 line · unSimple

OK, here is the new version.

That won't do, your original patch description should be here.
And it should be a fresh posting with [PATCH v2] in the subject.

Quoted 2 lines

---

You need to describe what changes between v1 and v2 here...

arch/mips/sgi-ip22/ip22-gio.c static void ip22_check_gio(int slotno, unsigned long addr, int irq) · line 366

Quoted 12 lines

 arch/mips/sgi-ip22/ip22-gio.c | 4 ++++

 1 file changed, 4 insertions(+)
arch/mips/sgi-ip22/ip22-gio.c +1 -0
index dfc52f6..f94f58b 100644
@@ -363,6 +363,10 @@ 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);
+

No need for empty line here.

arch/mips/sgi-ip22/ip22-gio.c static void ip22_check_gio(int slotno, unsigned long addr, int irq) · line 368

Quoted 2 lines
arch/mips/sgi-ip22/ip22-gio.c +2 -0
+if (!gio_dev)
+return;

Hm, the tabs were there but they got eaten when I replied.
Your mail seems to be base64-encoded which I don't think is acceptable for patches -- they should be posted as plain text.

[...]

MBR, Sergey