From: Julia Lawall Date: Tue, 22 Sep 2009 23:47:39 +0000 (-0700) Subject: drivers/video: add kmalloc NULL tests X-Git-Tag: v2.6.32-rc1~197 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ff8147fe71246b81a48de5f37041b026b57d60ca;p=platform%2Fkernel%2Flinux-stable.git drivers/video: 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/) // @@ 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 ) // [akpm@linux-foundation.org: convert to kstrdup() as well] Signed-off-by: Julia Lawall Cc: Ming Lei Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/drivers/video/au1100fb.c b/drivers/video/au1100fb.c index 378f277..a699aab 100644 --- a/drivers/video/au1100fb.c +++ b/drivers/video/au1100fb.c @@ -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 {