PageRenderTime 21ms CodeModel.GetById 16ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/scripts/coccinelle/null/kmerr.cocci

http://github.com/mirrors/linux
Unknown | 72 lines | 60 code | 12 blank | 0 comment | 0 complexity | 2607fd29cca6c7280624fc71576f80d8 MD5 | raw file
 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
15virtual context
16virtual org
17virtual report
18
19@withtest@
20expression x;
21position p;
22identifier f,fld;
23@@
24
25x@p = f(...);
26... when != x->fld
27\(x == NULL \| x != NULL\)
28
29@fixed depends on context && !org && !report@
30expression x,x1;
31position p1 != withtest.p;
32statement S;
33position any withtest.p;
34identifier f;
35@@
36
37*x@p1 = \(kmalloc\|kzalloc\|kcalloc\)(...);
38...
39*x1@p = f(...);
40if (!x1) S
41
42// ------------------------------------------------------------------------
43
44@rfixed depends on (org || report) && !context exists@
45expression x,x1;
46position p1 != withtest.p;
47position p2;
48statement S;
49position any withtest.p;
50identifier f;
51@@
52
53x@p1 = \(kmalloc\|kzalloc\|kcalloc\)(...);
54...
55x1@p = f@p2(...);
56if (!x1) S
57
58@script:python depends on org@
59p1 << rfixed.p1;
60p2 << rfixed.p2;
61@@
62
63cocci.print_main("alloc call",p1)
64cocci.print_secs("possible model",p2)
65
66@script:python depends on report@
67p1 << rfixed.p1;
68p2 << rfixed.p2;
69@@
70
71msg = "alloc with no test, possible model on line %s" % (p2[0].line)
72coccilib.report.print_report(p1[0],msg)