xref: /openbmc/linux/scripts/coccinelle/free/iounmap.cocci (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
17f904d7eSThomas Gleixner// SPDX-License-Identifier: GPL-2.0-only
2cd0207a7SJulia Lawall/// Find missing iounmaps.
3cd0207a7SJulia Lawall///
4cd0207a7SJulia Lawall//# This only signals a missing iounmap when there is an iounmap later
5cd0207a7SJulia Lawall//# in the same function.
6cd0207a7SJulia Lawall//# False positives can be due to loops.
7cd0207a7SJulia Lawall//
8cd0207a7SJulia Lawall// Confidence: Moderate
97f904d7eSThomas Gleixner// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6.
107f904d7eSThomas Gleixner// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6.
11*f01701ceSJulia Lawall// URL: https://coccinelle.gitlabpages.inria.fr/website
12cd0207a7SJulia Lawall// Comments:
13cd0207a7SJulia Lawall// Options:
14cd0207a7SJulia Lawall
15cd0207a7SJulia Lawallvirtual context
16cd0207a7SJulia Lawallvirtual org
17cd0207a7SJulia Lawallvirtual report
18cd0207a7SJulia Lawall
19cd0207a7SJulia Lawall@iom@
20cd0207a7SJulia Lawallexpression e;
21cd0207a7SJulia Lawallstatement S,S1;
22cd0207a7SJulia Lawallint ret;
23cd0207a7SJulia Lawallposition p1,p2,p3;
24cd0207a7SJulia Lawall@@
25cd0207a7SJulia Lawall
264bdc0d67SChristoph Hellwige = \(ioremap@p1\)(...)
27cd0207a7SJulia Lawall... when != iounmap(e)
28cd0207a7SJulia Lawallif (<+...e...+>) S
29cd0207a7SJulia Lawall... when any
30cd0207a7SJulia Lawall    when != iounmap(e)
31cd0207a7SJulia Lawall    when != if (...) { ... iounmap(e); ... }
32cd0207a7SJulia Lawall(
33cd0207a7SJulia Lawall if (ret == 0) S1
34cd0207a7SJulia Lawall|
35cd0207a7SJulia Lawallif (...)
36cd0207a7SJulia Lawall   { ...
37cd0207a7SJulia Lawall     return 0; }
38cd0207a7SJulia Lawall|
39cd0207a7SJulia Lawallif (...)
40cd0207a7SJulia Lawall   { ...
41cd0207a7SJulia Lawall     return <+...e...+>; }
42cd0207a7SJulia Lawall|
43cd0207a7SJulia Lawall*if@p2 (...)
44cd0207a7SJulia Lawall   { ... when != iounmap(e)
45cd0207a7SJulia Lawall         when forall
46cd0207a7SJulia Lawall     return@p3 ...; }
47cd0207a7SJulia Lawall)
48cd0207a7SJulia Lawall... when any
49cd0207a7SJulia Lawalliounmap(e);
50cd0207a7SJulia Lawall
51cd0207a7SJulia Lawall@script:python depends on org@
52cd0207a7SJulia Lawallp1 << iom.p1;
53cd0207a7SJulia Lawallp2 << iom.p2;
54cd0207a7SJulia Lawallp3 << iom.p3;
55cd0207a7SJulia Lawall@@
56cd0207a7SJulia Lawall
57cd0207a7SJulia Lawallcocci.print_main("ioremap",p1)
58cd0207a7SJulia Lawallcocci.print_secs("if",p2)
59cd0207a7SJulia Lawallcocci.print_secs("needed iounmap",p3)
60cd0207a7SJulia Lawall
61cd0207a7SJulia Lawall@script:python depends on report@
62cd0207a7SJulia Lawallp1 << iom.p1;
63cd0207a7SJulia Lawallp2 << iom.p2;
64cd0207a7SJulia Lawallp3 << iom.p3;
65cd0207a7SJulia Lawall@@
66cd0207a7SJulia Lawall
67cd0207a7SJulia Lawallmsg = "ERROR: missing iounmap; ioremap on line %s and execution via conditional on line %s" % (p1[0].line,p2[0].line)
68cd0207a7SJulia Lawallcoccilib.report.print_report(p3[0],msg)
69