Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /// The various basic memory allocation functions don't return ERR_PTR
0003 ///
0004 // Confidence: High
0005 // Copyright: (C) 2010-2012 Nicolas Palix.
0006 // Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6.
0007 // Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6.
0008 // URL: https://coccinelle.gitlabpages.inria.fr/website
0009 // Comments:
0010 // Options: --no-includes --include-headers
0011 
0012 virtual patch
0013 virtual context
0014 virtual org
0015 virtual report
0016 
0017 @depends on patch@
0018 expression x,E;
0019 @@
0020 
0021 x = \(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\|kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\)(...)
0022 ... when != x = E
0023 - IS_ERR(x)
0024 + !x
0025 
0026 @r depends on !patch exists@
0027 expression x,E;
0028 position p1,p2;
0029 @@
0030 
0031 *x = \(kmalloc@p1\|kzalloc@p1\|kcalloc@p1\|kmem_cache_alloc@p1\|kmem_cache_zalloc@p1\|kmem_cache_alloc_node@p1\|kmalloc_node@p1\|kzalloc_node@p1\)(...)
0032 ... when != x = E
0033 * IS_ERR@p2(x)
0034 
0035 @script:python depends on org@
0036 p1 << r.p1;
0037 p2 << r.p2;
0038 @@
0039 
0040 cocci.print_main("alloc call",p1)
0041 cocci.print_secs("IS_ERR that should be NULL tests",p2)
0042 
0043 @script:python depends on report@
0044 p1 << r.p1;
0045 p2 << r.p2;
0046 @@
0047 
0048 msg = "ERROR: allocation function on line %s returns NULL not ERR_PTR on failure" % (p1[0].line)
0049 coccilib.report.print_report(p2[0], msg)