1 // SPDX-License-Identifier: GPL-2.0-only
2 /// Remove casting the values returned by memory allocation functions
3 /// like kmalloc, kzalloc, kmem_cache_alloc, kmem_cache_zalloc etc.
5 //# This makes an effort to find cases of casting of values returned by
6 //# malloc, calloc, kmalloc, kmalloc_array, kmalloc_node and removes
7 //# the casting as it is not required. The result in the patch case may
8 //# need some reformatting.
11 // Copyright: (C) 2014 Himangi Saraogi
12 // Copyright: (C) 2017 Himanshu Jha
14 // Options: --no-includes --include-headers
26 m = re.compile(pattern)
28 @r1 depends on context || patch@
33 \(malloc\|calloc\|kmalloc\|kmalloc_array\|kmalloc_node\)(...)
35 //----------------------------------------------------------
37 //----------------------------------------------------------
39 @script:python depends on context@
43 if m.search(t) != None:
44 cocci.include_match(False)
46 @depends on context && r1@
51 \(malloc\|calloc\|kmalloc\|kmalloc_array\|kmalloc_node\)(...)
53 //----------------------------------------------------------
55 //----------------------------------------------------------
57 @script:python depends on patch@
61 if m.search(t) != None:
62 cocci.include_match(False)
64 @depends on patch && r1@
69 \(malloc\|calloc\|kmalloc\|kmalloc_array\|kmalloc_node\)(...)
71 //----------------------------------------------------------
72 // For org and report mode
73 //----------------------------------------------------------
75 @r2 depends on org || report@
81 \(malloc\|calloc\|kmalloc\|kmalloc_array\|kmalloc_node\)(...)
83 @script:python depends on org@
88 if m.search(t) != None:
89 cocci.include_match(False)
91 coccilib.org.print_safe_todo(p[0], t)
93 @script:python depends on report@
98 if m.search(t) != None:
99 cocci.include_match(False)
101 msg="WARNING: casting value returned by memory allocation function to (%s *) is useless." % (t)
102 coccilib.report.print_report(p[0], msg)