aboutsummaryrefslogtreecommitdiff
path: root/scripts/coccinelle/memory-region-housekeeping.cocci
blob: 5e6b31d8ba28d53bc45a553f28913f32722a31eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
  Usage:

    spatch \
        --macro-file scripts/cocci-macro-file.h \
        --sp-file scripts/coccinelle/memory-region-housekeeping.cocci \
        --keep-comments \
        --in-place \
        --dir .

*/


// Replace memory_region_init_ram(readonly) by memory_region_init_rom()
@@
expression E1, E2, E3, E4, E5;
symbol true;
@@
(
- memory_region_init_ram(E1, E2, E3, E4, E5);
+ memory_region_init_rom(E1, E2, E3, E4, E5);
  ... WHEN != E1
- memory_region_set_readonly(E1, true);
|
- memory_region_init_ram_nomigrate(E1, E2, E3, E4, E5);
+ memory_region_init_rom_nomigrate(E1, E2, E3, E4, E5);
  ... WHEN != E1
- memory_region_set_readonly(E1, true);
)


@possible_memory_region_init_rom@
expression E1, E2, E3, E4, E5;
position p;
@@
(
  memory_region_init_ram@p(E1, E2, E3, E4, E5);
  ...
  memory_region_set_readonly(E1, true);
|
  memory_region_init_ram_nomigrate@p(E1, E2, E3, E4, E5);
  ...
  memory_region_set_readonly(E1, true);
)
@script:python@
p << possible_memory_region_init_rom.p;
@@
cocci.print_main("potential use of memory_region_init_rom*() in ", p)


// Do not call memory_region_set_readonly() on ROM alias
@@
expression ROM, E1, E2, E3, E4;
expression ALIAS, E5, E6, E7, E8;
@@
(
  memory_region_init_rom(ROM, E1, E2, E3, E4);
|
  memory_region_init_rom_nomigrate(ROM, E1, E2, E3, E4);
)
  ...
   memory_region_init_alias(ALIAS, E5, E6, ROM, E7, E8);
-  memory_region_set_readonly(ALIAS, true);


// Replace by-hand memory_region_init_ram_nomigrate/vmstate_register_ram
// code sequences with use of the new memory_region_init_ram function.
// Similarly for the _rom and _rom_device functions.
// We don't try to replace sequences with a non-NULL owner, because
// there are none in the tree that can be automatically converted
// (and only a handful that can be manually converted).
@@
expression MR;
expression NAME;
expression SIZE;
expression ERRP;
@@
-memory_region_init_ram_nomigrate(MR, NULL, NAME, SIZE, ERRP);
+memory_region_init_ram(MR, NULL, NAME, SIZE, ERRP);
 ...
-vmstate_register_ram_global(MR);
@@
expression MR;
expression NAME;
expression SIZE;
expression ERRP;
@@
-memory_region_init_rom_nomigrate(MR, NULL, NAME, SIZE, ERRP);
+memory_region_init_rom(MR, NULL, NAME, SIZE, ERRP);
 ...
-vmstate_register_ram_global(MR);
@@
expression MR;
expression OPS;
expression OPAQUE;
expression NAME;
expression SIZE;
expression ERRP;
@@
-memory_region_init_rom_device_nomigrate(MR, NULL, OPS, OPAQUE, NAME, SIZE, ERRP);
+memory_region_init_rom_device(MR, NULL, OPS, OPAQUE, NAME, SIZE, ERRP);
 ...
-vmstate_register_ram_global(MR);