1/// Reimplement a call to devm_request_mem_region followed by a call to ioremap
2/// or ioremap_nocache by a call to devm_request_and_ioremap.
3/// Devm_request_and_ioremap was introduced in
4/// 72f8c0bfa0de64c68ee59f40eb9b2683bffffbb0.  It makes the code much more
5/// concise.
6///
7///
8// Confidence: High
9// Copyright: (C) 2011 Julia Lawall, INRIA/LIP6.  GPLv2.
10// Copyright: (C) 2011 Gilles Muller, INRIA/LiP6.  GPLv2.
11// URL: http://coccinelle.lip6.fr/
12// Comments:
13// Options: -no_includes -include_headers
14
15virtual patch
16virtual org
17virtual report
18virtual context
19
20@nm@
21expression myname;
22identifier i;
23@@
24
25struct platform_driver i = { .driver = { .name = myname } };
26
27@depends on patch@
28expression dev,res,size;
29@@
30
31-if (!devm_request_mem_region(dev, res->start, size,
32-                              \(res->name\|dev_name(dev)\))) {
33-   ...
34-   return ...;
35-}
36... when != res->start
37(
38-devm_ioremap(dev,res->start,size)
39+devm_request_and_ioremap(dev,res)
40|
41-devm_ioremap_nocache(dev,res->start,size)
42+devm_request_and_ioremap(dev,res)
43)
44... when any
45    when != res->start
46
47// this rule is separate from the previous one, because a single file can
48// have multiple values of myname
49@depends on patch@
50expression dev,res,size;
51expression nm.myname;
52@@
53
54-if (!devm_request_mem_region(dev, res->start, size,myname)) {
55-   ...
56-   return ...;
57-}
58... when != res->start
59(
60-devm_ioremap(dev,res->start,size)
61+devm_request_and_ioremap(dev,res)
62|
63-devm_ioremap_nocache(dev,res->start,size)
64+devm_request_and_ioremap(dev,res)
65)
66... when any
67    when != res->start
68
69
70@pb depends on org || report || context@
71expression dev,res,size;
72expression nm.myname;
73position p1,p2;
74@@
75
76*if
77  (!devm_request_mem_region@p1(dev, res->start, size,
78                              \(res->name\|dev_name(dev)\|myname\))) {
79   ...
80   return ...;
81}
82... when != res->start
83(
84*devm_ioremap@p2(dev,res->start,size)
85|
86*devm_ioremap_nocache@p2(dev,res->start,size)
87)
88... when any
89    when != res->start
90
91@script:python depends on org@
92p1 << pb.p1;
93p2 << pb.p2;
94@@
95
96cocci.print_main("INFO: replace by devm_request_and_ioremap",p1)
97cocci.print_secs("",p2)
98
99@script:python depends on report@
100p1 << pb.p1;
101p2 << pb.p2;
102@@
103
104msg = "INFO: devm_request_mem_region followed by ioremap on line %s can be replaced by devm_request_and_ioremap" % (p2[0].line)
105coccilib.report.print_report(p1[0],msg)
106