xref: /openbmc/linux/scripts/coccinelle/null/kmerr.cocci (revision 2e1e1605fc60b3fcf1e9382729a92fc305727952)
1*2e1e1605SNicolas Palix/// This semantic patch looks for kmalloc etc that are not followed by a
2*2e1e1605SNicolas Palix/// NULL check.  It only gives a report in the case where there is some
3*2e1e1605SNicolas Palix/// error handling code later in the function, which may be helpful
4*2e1e1605SNicolas Palix/// in determining what the error handling code for the call to kmalloc etc
5*2e1e1605SNicolas Palix/// should be.
6*2e1e1605SNicolas Palix///
7*2e1e1605SNicolas Palix// Confidence: High
8*2e1e1605SNicolas Palix// Copyright: (C) 2010 Nicolas Palix, DIKU.  GPLv2.
9*2e1e1605SNicolas Palix// Copyright: (C) 2010 Julia Lawall, DIKU.  GPLv2.
10*2e1e1605SNicolas Palix// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6.  GPLv2.
11*2e1e1605SNicolas Palix// URL: http://coccinelle.lip6.fr/
12*2e1e1605SNicolas Palix// Comments:
13*2e1e1605SNicolas Palix// Options: -no_includes -include_headers
14*2e1e1605SNicolas Palix
15*2e1e1605SNicolas Palixvirtual context
16*2e1e1605SNicolas Palixvirtual org
17*2e1e1605SNicolas Palixvirtual report
18*2e1e1605SNicolas Palix
19*2e1e1605SNicolas Palix@withtest@
20*2e1e1605SNicolas Palixexpression x;
21*2e1e1605SNicolas Palixposition p;
22*2e1e1605SNicolas Palixidentifier f,fld;
23*2e1e1605SNicolas Palix@@
24*2e1e1605SNicolas Palix
25*2e1e1605SNicolas Palixx@p = f(...);
26*2e1e1605SNicolas Palix... when != x->fld
27*2e1e1605SNicolas Palix\(x == NULL \| x != NULL\)
28*2e1e1605SNicolas Palix
29*2e1e1605SNicolas Palix@fixed depends on context && !org && !report@
30*2e1e1605SNicolas Palixexpression x,x1;
31*2e1e1605SNicolas Palixposition p1 != withtest.p;
32*2e1e1605SNicolas Palixstatement S;
33*2e1e1605SNicolas Palixposition any withtest.p;
34*2e1e1605SNicolas Palixidentifier f;
35*2e1e1605SNicolas Palix@@
36*2e1e1605SNicolas Palix
37*2e1e1605SNicolas Palix*x@p1 = \(kmalloc\|kzalloc\|kcalloc\)(...);
38*2e1e1605SNicolas Palix...
39*2e1e1605SNicolas Palix*x1@p = f(...);
40*2e1e1605SNicolas Palixif (!x1) S
41*2e1e1605SNicolas Palix
42*2e1e1605SNicolas Palix// ------------------------------------------------------------------------
43*2e1e1605SNicolas Palix
44*2e1e1605SNicolas Palix@rfixed depends on (org || report) && !context exists@
45*2e1e1605SNicolas Palixexpression x,x1;
46*2e1e1605SNicolas Palixposition p1 != withtest.p;
47*2e1e1605SNicolas Palixposition p2;
48*2e1e1605SNicolas Palixstatement S;
49*2e1e1605SNicolas Palixposition any withtest.p;
50*2e1e1605SNicolas Palixidentifier f;
51*2e1e1605SNicolas Palix@@
52*2e1e1605SNicolas Palix
53*2e1e1605SNicolas Palixx@p1 = \(kmalloc\|kzalloc\|kcalloc\)(...);
54*2e1e1605SNicolas Palix...
55*2e1e1605SNicolas Palixx1@p = f@p2(...);
56*2e1e1605SNicolas Palixif (!x1) S
57*2e1e1605SNicolas Palix
58*2e1e1605SNicolas Palix@script:python depends on org@
59*2e1e1605SNicolas Palixp1 << rfixed.p1;
60*2e1e1605SNicolas Palixp2 << rfixed.p2;
61*2e1e1605SNicolas Palix@@
62*2e1e1605SNicolas Palix
63*2e1e1605SNicolas Palixcocci.print_main("alloc call",p1)
64*2e1e1605SNicolas Palixcocci.print_secs("possible model",p2)
65*2e1e1605SNicolas Palix
66*2e1e1605SNicolas Palix@script:python depends on report@
67*2e1e1605SNicolas Palixp1 << rfixed.p1;
68*2e1e1605SNicolas Palixp2 << rfixed.p2;
69*2e1e1605SNicolas Palix@@
70*2e1e1605SNicolas Palix
71*2e1e1605SNicolas Palixmsg = "alloc with no test, possible model on line %s" % (p2[0].line)
72*2e1e1605SNicolas Palixcoccilib.report.print_report(p1[0],msg)
73