arch/blackfin: Add kmalloc NULL tests

Check that the result of kmalloc is not NULL before passing it to other
functions.

In the first two cases, the new code returns -ENOMEM, which seems
compatible with what is done for similar functions for other architectures.

In the last two cases, the new code fails silently, ie just returns,
because the function has void return type.

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>
Signed-off-by: Sonic Zhang <sonic.zhang@analog.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>

authored by Julia Lawall and committed by Mike Frysinger 994e9a2e 5bc6e3cf

+8
+8
arch/blackfin/mach-common/smp.c
··· 211 return 0; 212 213 msg = kmalloc(sizeof(*msg), GFP_ATOMIC); 214 INIT_LIST_HEAD(&msg->list); 215 msg->call_struct.func = func; 216 msg->call_struct.info = info; ··· 254 cpu_set(cpu, callmap); 255 256 msg = kmalloc(sizeof(*msg), GFP_ATOMIC); 257 INIT_LIST_HEAD(&msg->list); 258 msg->call_struct.func = func; 259 msg->call_struct.info = info; ··· 291 return; 292 293 msg = kmalloc(sizeof(*msg), GFP_ATOMIC); 294 memset(msg, 0, sizeof(msg)); 295 INIT_LIST_HEAD(&msg->list); 296 msg->type = BFIN_IPI_RESCHEDULE; ··· 320 return; 321 322 msg = kmalloc(sizeof(*msg), GFP_ATOMIC); 323 memset(msg, 0, sizeof(msg)); 324 INIT_LIST_HEAD(&msg->list); 325 msg->type = BFIN_IPI_CPU_STOP;
··· 211 return 0; 212 213 msg = kmalloc(sizeof(*msg), GFP_ATOMIC); 214 + if (!msg) 215 + return -ENOMEM; 216 INIT_LIST_HEAD(&msg->list); 217 msg->call_struct.func = func; 218 msg->call_struct.info = info; ··· 252 cpu_set(cpu, callmap); 253 254 msg = kmalloc(sizeof(*msg), GFP_ATOMIC); 255 + if (!msg) 256 + return -ENOMEM; 257 INIT_LIST_HEAD(&msg->list); 258 msg->call_struct.func = func; 259 msg->call_struct.info = info; ··· 287 return; 288 289 msg = kmalloc(sizeof(*msg), GFP_ATOMIC); 290 + if (!msg) 291 + return; 292 memset(msg, 0, sizeof(msg)); 293 INIT_LIST_HEAD(&msg->list); 294 msg->type = BFIN_IPI_RESCHEDULE; ··· 314 return; 315 316 msg = kmalloc(sizeof(*msg), GFP_ATOMIC); 317 + if (!msg) 318 + return; 319 memset(msg, 0, sizeof(msg)); 320 INIT_LIST_HEAD(&msg->list); 321 msg->type = BFIN_IPI_CPU_STOP;