• Julia Lawall's avatar
    arch/blackfin: Add kmalloc NULL tests · 994e9a2e
    Julia Lawall authored
    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: default avatarJulia Lawall <julia@diku.dk>
    Signed-off-by: default avatarSonic Zhang <sonic.zhang@analog.com>
    Signed-off-by: default avatarMike Frysinger <vapier@gentoo.org>
    994e9a2e
smp.c 12 KB