• Julia Lawall's avatar
    PCI: introduce missing kfree · 0b3e7388
    Julia Lawall authored
    Error handling code following a kmalloc should free the allocated data.
    Since the subsequent code that could provoke an error does not use the
    allocated data, the allocation is just moved below it.
    
    The semantic match that finds the problem is as follows:
    (http://www.emn.fr/x-info/coccinelle/)
    
    // <smpl>
    @r exists@
    local idexpression x;
    statement S;
    expression E;
    identifier f,l;
    position p1,p2;
    expression *ptr != NULL;
    @@
    
    (
    if ((x@p1 = \(kmalloc\|kzalloc\|kcalloc\)(...)) == NULL) S
    |
    x@p1 = \(kmalloc\|kzalloc\|kcalloc\)(...);
    ...
    if (x == NULL) S
    )
    <... when != x
         when != if (...) { <+...x...+> }
    x->f = E
    ...>
    (
     return \(0\|<+...x...+>\|ptr\);
    |
     return@p2 ...;
    )
    
    @script:python@
    p1 << r.p1;
    p2 << r.p2;
    @@
    
    print "* file: %s kmalloc %s return %s" % (p1[0].file,p1[0].line,p2[0].line)
    // </smpl>
    Signed-off-by: default avatarJulia Lawall <julia@diku.dk>
    Reviewed-by: default avatarMatthew Wilcox <willy@linux.intel.com>
    Reviewed-by: default avatarKenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
    Signed-off-by: default avatarJesse Barnes <jbarnes@virtuousgeek.org>
    0b3e7388
pciehp_acpi.c 4.11 KB