Commit ff8147fe71246b81a48de5f37041b026b57d60ca
Committed by
Linus Torvalds
1 parent
f7a595e98c
Exists in
master
and in
4 other branches
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/) // <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> [akpm@linux-foundation.org: convert to kstrdup() as well] Signed-off-by: Julia Lawall <julia@diku.dk> Cc: Ming Lei <tom.leiming@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 5 additions and 2 deletions Side-by-side Diff
drivers/video/au1100fb.c
... | ... | @@ -715,8 +715,11 @@ |
715 | 715 | } |
716 | 716 | /* Mode option (only option that start with digit) */ |
717 | 717 | else if (isdigit(this_opt[0])) { |
718 | - mode = kmalloc(strlen(this_opt) + 1, GFP_KERNEL); | |
719 | - strncpy(mode, this_opt, strlen(this_opt) + 1); | |
718 | + mode = kstrdup(this_opt, GFP_KERNEL); | |
719 | + if (!mode) { | |
720 | + print_err("memory allocation failed"); | |
721 | + return -ENOMEM; | |
722 | + } | |
720 | 723 | } |
721 | 724 | /* Unsupported option */ |
722 | 725 | else { |