^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /// PTR_ERR should be applied before its argument is reassigned, typically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) /// to NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) ///
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) // Confidence: High
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) // Copyright: (C) 2012 Julia Lawall, INRIA/LIP6.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) // Copyright: (C) 2012 Gilles Muller, INRIA/LiP6.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) // URL: http://coccinelle.lip6.fr/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) // Comments:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) // Options: --no-includes --include-headers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) virtual org
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) virtual report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) virtual context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) @r exists@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) expression e,e1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) constant c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) position p1,p2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *e@p1 = c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) ... when != e = e1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) when != &e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) when != true IS_ERR(e)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) *PTR_ERR@p2(e)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) @script:python depends on org@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) p1 << r.p1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) p2 << r.p2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) cocci.print_main("PTR_ERR",p2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) cocci.print_secs("assignment",p1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) @script:python depends on report@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) p1 << r.p1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) p2 << r.p2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) msg = "ERROR: PTR_ERR applied after initialization to constant on line %s" % (p1[0].line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) coccilib.report.print_report(p2[0],msg)