Skip to content

Commit 1f648f8

Browse files
Wolfram Sanggregkh
authored andcommitted
coccinelle: api: add spatch to prevent unnecessary .owner
There are calls which silently set the owner of a module. This is the preferred way [1], so avoid setting it manually. Currently, we only care about platform drivers, but there might be more calls to be added later. [1] https://lkml.org/lkml/2014/10/12/87 Signed-off-by: Wolfram Sang <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 291f653 commit 1f648f8

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/// Remove .owner field if calls are used which set it automatically
2+
///
3+
// Confidence: High
4+
// Copyright: (C) 2014 Wolfram Sang. GPL v2.
5+
6+
virtual patch
7+
virtual context
8+
virtual org
9+
virtual report
10+
11+
@match1@
12+
declarer name module_platform_driver;
13+
declarer name module_platform_driver_probe;
14+
identifier __driver;
15+
@@
16+
(
17+
module_platform_driver(__driver);
18+
|
19+
module_platform_driver_probe(__driver, ...);
20+
)
21+
22+
@fix1 depends on match1 && patch && !context && !org && !report@
23+
identifier match1.__driver;
24+
@@
25+
static struct platform_driver __driver = {
26+
.driver = {
27+
- .owner = THIS_MODULE,
28+
}
29+
};
30+
31+
@match2@
32+
identifier __driver;
33+
@@
34+
(
35+
platform_driver_register(&__driver)
36+
|
37+
platform_driver_probe(&__driver, ...)
38+
|
39+
platform_create_bundle(&__driver, ...)
40+
)
41+
42+
@fix2 depends on match2 && patch && !context && !org && !report@
43+
identifier match2.__driver;
44+
@@
45+
static struct platform_driver __driver = {
46+
.driver = {
47+
- .owner = THIS_MODULE,
48+
}
49+
};
50+
51+
// ----------------------------------------------------------------------------
52+
53+
@fix1_context depends on match1 && !patch && (context || org || report)@
54+
identifier match1.__driver;
55+
position j0;
56+
@@
57+
58+
static struct platform_driver __driver = {
59+
.driver = {
60+
* .owner@j0 = THIS_MODULE,
61+
}
62+
};
63+
64+
@fix2_context depends on match2 && !patch && (context || org || report)@
65+
identifier match2.__driver;
66+
position j0;
67+
@@
68+
69+
static struct platform_driver __driver = {
70+
.driver = {
71+
* .owner@j0 = THIS_MODULE,
72+
}
73+
};
74+
75+
// ----------------------------------------------------------------------------
76+
77+
@script:python fix1_org depends on org@
78+
j0 << fix1_context.j0;
79+
@@
80+
81+
msg = "No need to set .owner here. The core will do it."
82+
coccilib.org.print_todo(j0[0], msg)
83+
84+
@script:python fix2_org depends on org@
85+
j0 << fix2_context.j0;
86+
@@
87+
88+
msg = "No need to set .owner here. The core will do it."
89+
coccilib.org.print_todo(j0[0], msg)
90+
91+
// ----------------------------------------------------------------------------
92+
93+
@script:python fix1_report depends on report@
94+
j0 << fix1_context.j0;
95+
@@
96+
97+
msg = "No need to set .owner here. The core will do it."
98+
coccilib.report.print_report(j0[0], msg)
99+
100+
@script:python fix2_report depends on report@
101+
j0 << fix2_context.j0;
102+
@@
103+
104+
msg = "No need to set .owner here. The core will do it."
105+
coccilib.report.print_report(j0[0], msg)
106+

0 commit comments

Comments
 (0)