diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/coccinelle/null/kmerr.cocci | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/scripts/coccinelle/null/kmerr.cocci b/scripts/coccinelle/null/kmerr.cocci new file mode 100644 index 00000000000..949bf656c64 --- /dev/null +++ b/scripts/coccinelle/null/kmerr.cocci | |||
@@ -0,0 +1,72 @@ | |||
1 | /// This semantic patch looks for kmalloc etc that are not followed by a | ||
2 | /// NULL check. It only gives a report in the case where there is some | ||
3 | /// error handling code later in the function, which may be helpful | ||
4 | /// in determining what the error handling code for the call to kmalloc etc | ||
5 | /// should be. | ||
6 | /// | ||
7 | // Confidence: High | ||
8 | // Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2. | ||
9 | // Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2. | ||
10 | // Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2. | ||
11 | // URL: http://coccinelle.lip6.fr/ | ||
12 | // Comments: | ||
13 | // Options: -no_includes -include_headers | ||
14 | |||
15 | virtual context | ||
16 | virtual org | ||
17 | virtual report | ||
18 | |||
19 | @withtest@ | ||
20 | expression x; | ||
21 | position p; | ||
22 | identifier f,fld; | ||
23 | @@ | ||
24 | |||
25 | x@p = f(...); | ||
26 | ... when != x->fld | ||
27 | \(x == NULL \| x != NULL\) | ||
28 | |||
29 | @fixed depends on context && !org && !report@ | ||
30 | expression x,x1; | ||
31 | position p1 != withtest.p; | ||
32 | statement S; | ||
33 | position any withtest.p; | ||
34 | identifier f; | ||
35 | @@ | ||
36 | |||
37 | *x@p1 = \(kmalloc\|kzalloc\|kcalloc\)(...); | ||
38 | ... | ||
39 | *x1@p = f(...); | ||
40 | if (!x1) S | ||
41 | |||
42 | // ------------------------------------------------------------------------ | ||
43 | |||
44 | @rfixed depends on (org || report) && !context exists@ | ||
45 | expression x,x1; | ||
46 | position p1 != withtest.p; | ||
47 | position p2; | ||
48 | statement S; | ||
49 | position any withtest.p; | ||
50 | identifier f; | ||
51 | @@ | ||
52 | |||
53 | x@p1 = \(kmalloc\|kzalloc\|kcalloc\)(...); | ||
54 | ... | ||
55 | x1@p = f@p2(...); | ||
56 | if (!x1) S | ||
57 | |||
58 | @script:python depends on org@ | ||
59 | p1 << rfixed.p1; | ||
60 | p2 << rfixed.p2; | ||
61 | @@ | ||
62 | |||
63 | cocci.print_main("alloc call",p1) | ||
64 | cocci.print_secs("possible model",p2) | ||
65 | |||
66 | @script:python depends on report@ | ||
67 | p1 << rfixed.p1; | ||
68 | p2 << rfixed.p2; | ||
69 | @@ | ||
70 | |||
71 | msg = "alloc with no test, possible model on line %s" % (p2[0].line) | ||
72 | coccilib.report.print_report(p1[0],msg) | ||