master
cocci 104 lines 2.62 KB
Raw
1 /*
2 Usage:
3
4 spatch \
5 --macro-file scripts/cocci-macro-file.h \
6 --sp-file scripts/coccinelle/memory-region-housekeeping.cocci \
7 --keep-comments \
8 --in-place \
9 --dir .
10
11 */
12
13
14 // Replace memory_region_init_ram(readonly) by memory_region_init_rom()
15 @@
16 expression E1, E2, E3, E4, E5;
17 symbol true;
18 @@
19 - memory_region_init_ram(E1, E2, E3, E4, E5);
20 + memory_region_init_rom(E1, E2, E3, E4, E5);
21 ... WHEN != E1
22 - memory_region_set_readonly(E1, true);
23
24
25 @possible_memory_region_init_rom@
26 expression E1, E2, E3, E4, E5;
27 position p;
28 @@
29 memory_region_init_ram@p(E1, E2, E3, E4, E5);
30 ...
31 memory_region_set_readonly(E1, true);
32 @script:python@
33 p << possible_memory_region_init_rom.p;
34 @@
35 cocci.print_main("potential use of memory_region_init_rom*() in ", p)
36
37
38 // Do not call memory_region_set_readonly() on ROM alias
39 @@
40 expression ROM, E1, E2, E3, E4;
41 expression ALIAS, E5, E6, E7, E8;
42 @@
43 memory_region_init_rom(ROM, E1, E2, E3, E4);
44 ...
45 memory_region_init_alias(ALIAS, E5, E6, ROM, E7, E8);
46 - memory_region_set_readonly(ALIAS, true);
47
48
49 // We don't try to replace sequences with a non-NULL owner, because
50 // there are none in the tree that can be automatically converted
51 // (and only a handful that can be manually converted).
52 @@
53 typedef DeviceState;
54 identifier device_fn, dev, obj;
55 expression E1, E2, E3, E4, E5;
56 @@
57 static void device_fn(DeviceState *dev, ...)
58 {
59 ...
60 Object *obj = OBJECT(dev);
61 <+...
62 (
63 - memory_region_init(E1, NULL, E2, E3);
64 + memory_region_init(E1, obj, E2, E3);
65 |
66 - memory_region_init_io(E1, NULL, E2, E3, E4, E5);
67 + memory_region_init_io(E1, obj, E2, E3, E4, E5);
68 |
69 - memory_region_init_alias(E1, NULL, E2, E3, E4, E5);
70 + memory_region_init_alias(E1, obj, E2, E3, E4, E5);
71 |
72 - memory_region_init_rom(E1, NULL, E2, E3, E4);
73 + memory_region_init_rom(E1, obj, E2, E3, E4);
74 |
75 - memory_region_init_ram_flags_nomigrate(E1, NULL, E2, E3, E4, E5);
76 + memory_region_init_ram_flags_nomigrate(E1, obj, E2, E3, E4, E5);
77 )
78 ...+>
79 }
80 @@
81 identifier device_fn, dev;
82 expression E1, E2, E3, E4, E5;
83 @@
84 static void device_fn(DeviceState *dev, ...)
85 {
86 <+...
87 (
88 - memory_region_init(E1, NULL, E2, E3);
89 + memory_region_init(E1, OBJECT(dev), E2, E3);
90 |
91 - memory_region_init_io(E1, NULL, E2, E3, E4, E5);
92 + memory_region_init_io(E1, OBJECT(dev), E2, E3, E4, E5);
93 |
94 - memory_region_init_alias(E1, NULL, E2, E3, E4, E5);
95 + memory_region_init_alias(E1, OBJECT(dev), E2, E3, E4, E5);
96 |
97 - memory_region_init_rom(E1, NULL, E2, E3, E4);
98 + memory_region_init_rom(E1, OBJECT(dev), E2, E3, E4);
99 |
100 - memory_region_init_ram_flags_nomigrate(E1, NULL, E2, E3, E4, E5);
101 + memory_region_init_ram_flags_nomigrate(E1, OBJECT(dev), E2, E3, E4, E5);
102 )
103 ...+>
104 }