Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ff8147fe authored by Julia Lawall's avatar Julia Lawall Committed by Linus Torvalds
Browse files

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: default avatarJulia Lawall <julia@diku.dk>
Cc: Ming Lei <tom.leiming@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent f7a595e9
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -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 {