Skip to content

Commit cc9a2c8

Browse files
Julia Lawallmattst88
authored andcommitted
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>
1 parent 04d8a9d commit cc9a2c8

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

‎arch/alpha/kernel/core_marvel.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,8 @@ marvel_agp_info(void)
11031103
* Allocate the info structure.
11041104
*/
11051105
agp = kmalloc(sizeof(*agp), GFP_KERNEL);
1106+
if (!agp)
1107+
return NULL;
11061108

11071109
/*
11081110
* Fill it in.

‎arch/alpha/kernel/core_titan.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,8 @@ titan_agp_info(void)
757757
* Allocate the info structure.
758758
*/
759759
agp = kmalloc(sizeof(*agp), GFP_KERNEL);
760+
if (!agp)
761+
return NULL;
760762

761763
/*
762764
* Fill it in.

0 commit comments

Comments
 (0)