Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / scripts / coccinelle / api / alloc / alloc_cast.cocci
1 /// Remove casting the values returned by memory allocation functions
2 /// like kmalloc, kzalloc, kmem_cache_alloc, kmem_cache_zalloc etc.
3 ///
4 //# This makes an effort to find cases of casting of values returned by
5 //# kmalloc, kzalloc, kcalloc, kmem_cache_alloc, kmem_cache_zalloc,
6 //# kmem_cache_alloc_node, kmalloc_node and kzalloc_node and removes
7 //# the casting as it is not required. The result in the patch case may
8 //#need some reformatting.
9 //
10 // Confidence: High
11 // Copyright: 2014, Himangi Saraogi  GPLv2.
12 // Comments:
13 // Options: --no-includes --include-headers
14 //
15
16 virtual context
17 virtual patch
18 virtual org
19 virtual report
20
21 //----------------------------------------------------------
22 //  For context mode
23 //----------------------------------------------------------
24
25 @depends on context@
26 type T;
27 @@
28
29 * (T *)
30   \(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\|
31    kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\)(...)
32
33 //----------------------------------------------------------
34 //  For patch mode
35 //----------------------------------------------------------
36
37 @depends on patch@
38 type T;
39 @@
40
41 - (T *)
42   (\(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\|
43    kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\)(...))
44
45 //----------------------------------------------------------
46 //  For org and report mode
47 //----------------------------------------------------------
48
49 @r depends on org || report@
50 type T;
51 position p;
52 @@
53
54  (T@p *)\(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\|
55    kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\)(...)
56
57 @script:python depends on org@
58 p << r.p;
59 t << r.T;
60 @@
61
62 coccilib.org.print_safe_todo(p[0], t)
63
64 @script:python depends on report@
65 p << r.p;
66 t << r.T;
67 @@
68
69 msg="WARNING: casting value returned by memory allocation function to (%s *) is useless." % (t)
70 coccilib.report.print_report(p[0], msg)
71
72