0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /// PTR_ERR should be applied before its argument is reassigned, typically
0003 /// to NULL
0004 ///
0005 // Confidence: High
0006 // Copyright: (C) 2012 Julia Lawall, INRIA/LIP6.
0007 // Copyright: (C) 2012 Gilles Muller, INRIA/LiP6.
0008 // URL: https://coccinelle.gitlabpages.inria.fr/website
0009 // Comments:
0010 // Options: --no-includes --include-headers
0011
0012 virtual org
0013 virtual report
0014 virtual context
0015
0016 @r exists@
0017 expression e,e1;
0018 constant c;
0019 position p1,p2;
0020 @@
0021
0022 *e@p1 = c
0023 ... when != e = e1
0024 when != &e
0025 when != true IS_ERR(e)
0026 *PTR_ERR@p2(e)
0027
0028 @script:python depends on org@
0029 p1 << r.p1;
0030 p2 << r.p2;
0031 @@
0032
0033 cocci.print_main("PTR_ERR",p2)
0034 cocci.print_secs("assignment",p1)
0035
0036 @script:python depends on report@
0037 p1 << r.p1;
0038 p2 << r.p2;
0039 @@
0040
0041 msg = "ERROR: PTR_ERR applied after initialization to constant on line %s" % (p1[0].line)
0042 coccilib.report.print_report(p2[0],msg)