Skip to content

Commit

Permalink
arch/alpha/kernel: Add kmalloc NULL tests
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Julia Lawall authored and Matt Turner committed Nov 30, 2009
1 parent 04d8a9d commit cc9a2c8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions arch/alpha/kernel/core_marvel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,8 @@ marvel_agp_info(void)
* Allocate the info structure.
*/
agp = kmalloc(sizeof(*agp), GFP_KERNEL);
if (!agp)
return NULL;

/*
* Fill it in.
Expand Down
2 changes: 2 additions & 0 deletions arch/alpha/kernel/core_titan.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,8 @@ titan_agp_info(void)
* Allocate the info structure.
*/
agp = kmalloc(sizeof(*agp), GFP_KERNEL);
if (!agp)
return NULL;

/*
* Fill it in.
Expand Down

0 comments on commit cc9a2c8

Please sign in to comment.