Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arch/alpha/kernel: Add kmalloc NULL tests

Check that the result of kmalloc is not NULL before passing it to other
functions.

The semantic match that finds this problem is as follows:
(http://www.emn.fr/x-info/coccinelle/)

// <smpl>
@@
expression *x;
identifier f;
constant char *C;
@@

x = \(kmalloc\|kcalloc\|kzalloc\)(...);
... when != x == NULL
when != x != NULL
when != (x || ...)
(
kfree(x)
f(...,C,...,x,...)
|
*f(...,x,...)
|
*x->f
)
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Richard Henderson <rth@twiddle.net>
Signed-off-by: Matt Turner <mattst88@gmail.com>

authored by

Julia Lawall and committed by
Matt Turner
cc9a2c83 04d8a9db

+4
+2
arch/alpha/kernel/core_marvel.c
··· 1103 1103 * Allocate the info structure. 1104 1104 */ 1105 1105 agp = kmalloc(sizeof(*agp), GFP_KERNEL); 1106 + if (!agp) 1107 + return NULL; 1106 1108 1107 1109 /* 1108 1110 * Fill it in.
+2
arch/alpha/kernel/core_titan.c
··· 757 757 * Allocate the info structure. 758 758 */ 759 759 agp = kmalloc(sizeof(*agp), GFP_KERNEL); 760 + if (!agp) 761 + return NULL; 760 762 761 763 /* 762 764 * Fill it in.