Skip to content

Commit

Permalink
drivers/video: 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>

[[email protected]: convert to kstrdup() as well]
Signed-off-by: Julia Lawall <[email protected]>
Cc: Ming Lei <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Julia Lawall authored and torvalds committed Sep 23, 2009
1 parent f7a595e commit ff8147f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions drivers/video/au1100fb.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,11 @@ int au1100fb_setup(char *options)
}
/* Mode option (only option that start with digit) */
else if (isdigit(this_opt[0])) {
mode = kmalloc(strlen(this_opt) + 1, GFP_KERNEL);
strncpy(mode, this_opt, strlen(this_opt) + 1);
mode = kstrdup(this_opt, GFP_KERNEL);
if (!mode) {
print_err("memory allocation failed");
return -ENOMEM;
}
}
/* Unsupported option */
else {
Expand Down

0 comments on commit ff8147f

Please sign in to comment.