Skip to content

Commit d09778d

Browse files
himanshujha199640masahir0y
authored andcommitted
coccinelle: api: add devm_platform_ioremap_resource script
Use recently introduced devm_platform_ioremap_resource helper which wraps platform_get_resource() and devm_ioremap_resource() together. This helps produce much cleaner code and remove local `struct resource` declaration. Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
1 parent 4bd01de commit d09778d

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/// Use devm_platform_ioremap_resource helper which wraps
3+
/// platform_get_resource() and devm_ioremap_resource() together.
4+
///
5+
// Confidence: High
6+
// Copyright: (C) 2019 Himanshu Jha GPLv2.
7+
// Copyright: (C) 2019 Julia Lawall, Inria/LIP6. GPLv2.
8+
// Keywords: platform_get_resource, devm_ioremap_resource,
9+
// Keywords: devm_platform_ioremap_resource
10+
11+
virtual patch
12+
virtual report
13+
14+
@r depends on patch && !report@
15+
expression e1, e2, arg1, arg2, arg3;
16+
identifier id;
17+
@@
18+
19+
(
20+
- id = platform_get_resource(arg1, IORESOURCE_MEM, arg2);
21+
|
22+
- struct resource *id = platform_get_resource(arg1, IORESOURCE_MEM, arg2);
23+
)
24+
... when != id
25+
- e1 = devm_ioremap_resource(arg3, id);
26+
+ e1 = devm_platform_ioremap_resource(arg1, arg2);
27+
... when != id
28+
? id = e2
29+
30+
@r1 depends on patch && !report@
31+
identifier r.id;
32+
type T;
33+
@@
34+
35+
- T *id;
36+
...when != id
37+
38+
@r2 depends on report && !patch@
39+
identifier id;
40+
expression e1, e2, arg1, arg2, arg3;
41+
position j0;
42+
@@
43+
44+
(
45+
id = platform_get_resource(arg1, IORESOURCE_MEM, arg2);
46+
|
47+
struct resource *id = platform_get_resource(arg1, IORESOURCE_MEM, arg2);
48+
)
49+
... when != id
50+
e1@j0 = devm_ioremap_resource(arg3, id);
51+
... when != id
52+
? id = e2
53+
54+
@script:python depends on report && !patch@
55+
e1 << r2.e1;
56+
j0 << r2.j0;
57+
@@
58+
59+
msg = "WARNING: Use devm_platform_ioremap_resource for %s" % (e1)
60+
coccilib.report.print_report(j0[0], msg)

0 commit comments

Comments
 (0)