xref: /openbmc/linux/scripts/coccinelle/misc/cstptr.cocci (revision 93f14468491747d6d3efd0b3a42785b1d51a127a)
14a05f067SJulia Lawall/// PTR_ERR should be applied before its argument is reassigned, typically
24a05f067SJulia Lawall/// to NULL
34a05f067SJulia Lawall///
44a05f067SJulia Lawall// Confidence: High
54a05f067SJulia Lawall// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6.  GPLv2.
64a05f067SJulia Lawall// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6.  GPLv2.
74a05f067SJulia Lawall// URL: http://coccinelle.lip6.fr/
84a05f067SJulia Lawall// Comments:
9*93f14468SNicolas Palix// Options: --no-includes --include-headers
104a05f067SJulia Lawall
114a05f067SJulia Lawallvirtual org
124a05f067SJulia Lawallvirtual report
134a05f067SJulia Lawallvirtual context
144a05f067SJulia Lawall
154a05f067SJulia Lawall@r exists@
164a05f067SJulia Lawallexpression e,e1;
174a05f067SJulia Lawallconstant c;
184a05f067SJulia Lawallposition p1,p2;
194a05f067SJulia Lawall@@
204a05f067SJulia Lawall
214a05f067SJulia Lawall*e@p1 = c
224a05f067SJulia Lawall... when != e = e1
234a05f067SJulia Lawall    when != &e
244a05f067SJulia Lawall    when != true IS_ERR(e)
254a05f067SJulia Lawall*PTR_ERR@p2(e)
264a05f067SJulia Lawall
274a05f067SJulia Lawall@script:python depends on org@
284a05f067SJulia Lawallp1 << r.p1;
294a05f067SJulia Lawallp2 << r.p2;
304a05f067SJulia Lawall@@
314a05f067SJulia Lawall
324a05f067SJulia Lawallcocci.print_main("PTR_ERR",p2)
334a05f067SJulia Lawallcocci.print_secs("assignment",p1)
344a05f067SJulia Lawall
354a05f067SJulia Lawall@script:python depends on report@
364a05f067SJulia Lawallp1 << r.p1;
374a05f067SJulia Lawallp2 << r.p2;
384a05f067SJulia Lawall@@
394a05f067SJulia Lawall
404a05f067SJulia Lawallmsg = "ERROR: PTR_ERR applied after initialization to constant on line %s" % (p1[0].line)
414a05f067SJulia Lawallcoccilib.report.print_report(p2[0],msg)
42