summaryrefslogtreecommitdiffstats
path: root/scripts/coccinelle/api/alloc/drop_kmalloc_cast.cocci
blob: bd5d08b882ee9ccda1d79da6f596e34f0ec12ef1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
///
/// Casting (void *) value returned by kmalloc is useless
/// as mentioned in Documentation/CodingStyle, Chap 14.
///
// Confidence: High
// Copyright: 2009,2010 Nicolas Palix, DIKU.  GPLv2.
// URL: http://coccinelle.lip6.fr/
// Options: --no-includes --include-headers
//
// Keywords: kmalloc, kzalloc, kcalloc
// Version min: < 2.6.12 kmalloc
// Version min: < 2.6.12 kcalloc
// Version min:   2.6.14 kzalloc
//

virtual context
virtual patch
virtual org
virtual report

//----------------------------------------------------------
//  For context mode
//----------------------------------------------------------

@depends on context@
type T;
@@

* (T *)
  \(kmalloc\|kzalloc\|kcalloc\)(...)

//----------------------------------------------------------
//  For patch mode
//----------------------------------------------------------

@depends on patch@
type T;
@@

- (T *)
  \(kmalloc\|kzalloc\|kcalloc\)(...)

//----------------------------------------------------------
//  For org and report mode
//----------------------------------------------------------

@r depends on org || report@
type T;
position p;
@@

 (T@p *)\(kmalloc\|kzalloc\|kcalloc\)(...)

@script:python depends on org@
p << r.p;
t << r.T;
@@

coccilib.org.print_safe_todo(p[0], t)

@script:python depends on report@
p << r.p;
t << r.T;
@@

msg="WARNING: casting value returned by k[cmz]alloc to (%s *) is useless." % (t)
coccilib.report.print_report(p[0], msg)