diff options
author | Julia Lawall <Julia.Lawall@lip6.fr> | 2011-12-27 12:28:50 -0500 |
---|---|---|
committer | Michal Marek <mmarek@suse.cz> | 2012-01-14 16:39:53 -0500 |
commit | 22e0059af301ec163d563c3590d2277c2a557d4f (patch) | |
tree | 6ac7178b9f2ef6a6210f98f92020e7987ac8bc28 /scripts | |
parent | f95ab20972cfefa8ee5428d6c3afd4cb8eacabf4 (diff) |
coccinelle: semantic patches related to devm_ functions (part 1)
devm_ functions allocate memory that is to remain allocated until the
device is detached. This patch checks for opportunities for using the
function devm_request_and_ioremap.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/coccinelle/api/devm_request_and_ioremap.cocci | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/scripts/coccinelle/api/devm_request_and_ioremap.cocci b/scripts/coccinelle/api/devm_request_and_ioremap.cocci new file mode 100644 index 000000000000..46beb81406ab --- /dev/null +++ b/scripts/coccinelle/api/devm_request_and_ioremap.cocci | |||
@@ -0,0 +1,105 @@ | |||
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 | |||
15 | virtual patch | ||
16 | virtual org | ||
17 | virtual report | ||
18 | virtual context | ||
19 | |||
20 | @nm@ | ||
21 | expression myname; | ||
22 | identifier i; | ||
23 | @@ | ||
24 | |||
25 | struct platform_driver i = { .driver = { .name = myname } }; | ||
26 | |||
27 | @depends on patch@ | ||
28 | expression 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@ | ||
50 | expression dev,res,size; | ||
51 | expression 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@ | ||
71 | expression dev,res,size; | ||
72 | expression nm.myname; | ||
73 | position 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@ | ||
92 | p1 << pb.p1; | ||
93 | p2 << pb.p2; | ||
94 | @@ | ||
95 | |||
96 | cocci.print_main("INFO: replace by devm_request_and_ioremap",p1) | ||
97 | cocci.print_secs("",p2) | ||
98 | |||
99 | @script:python depends on report@ | ||
100 | p1 << pb.p1; | ||
101 | p2 << pb.p2; | ||
102 | @@ | ||
103 | |||
104 | msg = "INFO: devm_request_mem_region followed by ioremap on line %s can be replaced by devm_request_and_ioremap" % (p2[0].line) | ||
105 | coccilib.report.print_report(p1[0],msg) | ||