forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ms_timeout.cocci
194 lines (177 loc) · 3.28 KB
/
ms_timeout.cocci
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// Copyright (c) 2019-2020 Nordic Semiconductor ASA
// SPDX-License-Identifer: Apache-2.0
// Replace use of K_NO_WAIT and K_FOREVER in API that requires
// timeouts be specified as integral milliseconds.
//
// These constants used to have the values 0 and -1 respectively; they
// are now timeout values which are opaque non-integral values that
// can't be converted to integers automatically. For K_NO_WAIT replace
// with 0; for K_FOREVER replace with SYS_FOREVER_MS, the value of
// which is -1.
//
// Options: --include-headers
virtual patch
virtual report
// ** Handle millisecond timeout as the last parameter
// Match identifer passed as timeout
@match_fn_l1@
identifier fn =~ "(?x)^
(dmic_read
|bt_buf_get_(rx|cmd_complete|evt)
|bt_mesh_cfg_cli_timeout_set
|isotp_(bind|recv(_net)?|send(_net)?(_ctx)?_buf)
|tty_set_(tx|rx)_timeout
|can_(write|recover)
|uart_(tx|rx_enable)
|dns_(resolve_name|get_addr_info)
|net_config_init
|net_ppp_ping
|websocket_(send|recv)_msg
)$";
identifier T;
@@
fn(..., T);
@report_fn_l1
extends match_fn_l1
depends on report
@
identifier K_NO_WAIT =~ "^K_NO_WAIT$";
identifier K_FOREVER =~ "^K_FOREVER$";
position p;
@@
fn@p(...,
(
K_NO_WAIT
|
K_FOREVER
)
)
@script:python
depends on report
@
fn << match_fn_l1.fn;
T << match_fn_l1.T;
p << report_fn_l1.p;
@@
msg = "WARNING: [msl1] replace constant {} with ms duration in {}".format(T, fn)
coccilib.report.print_report(p[0], msg);
@fix_fn_l1
extends match_fn_l1
depends on patch
@
identifier K_NO_WAIT =~ "^K_NO_WAIT$";
identifier K_FOREVER =~ "^K_FOREVER$";
@@
fn(...,
(
- K_NO_WAIT
+ 0
|
- K_FOREVER
+ SYS_FOREVER_MS
))
// ** Handle millisecond timeout as second from last parameter
// Match identifer passed as timeout
@match_fn_l2@
identifier fn =~ "(?x)^
(http_client_req
|websocket_connect
)$";
expression L1;
identifier T;
@@
fn(..., T, L1)
@report_fn_l2
extends match_fn_l2
depends on report
@
identifier K_NO_WAIT =~ "^K_NO_WAIT$";
identifier K_FOREVER =~ "^K_FOREVER$";
expression X1;
position p;
@@
fn@p(...,
(
K_NO_WAIT
|
K_FOREVER
)
, X1)
@script:python
depends on report
@
fn << match_fn_l2.fn;
T << match_fn_l2.T;
p << report_fn_l2.p;
@@
msg = "WARNING: [msl2] replace constant {} with ms duration in {}".format(T, fn)
coccilib.report.print_report(p[0], msg);
@fix_fn_l2
extends match_fn_l2
depends on patch
@
identifier K_NO_WAIT =~ "^K_NO_WAIT$";
identifier K_FOREVER =~ "^K_FOREVER$";
expression X1;
@@
fn(...,
(
- K_NO_WAIT
+ 0
|
- K_FOREVER
+ SYS_FOREVER_MS
)
, X1)
// ** Handle millisecond timeout as third from last parameter
// Match identifer passed as timeout
@match_fn_l3@
identifier fn =~ "(?x)^
(can_send
|lora_recv
)$";
expression L1;
expression L2;
identifier T;
@@
fn(..., T, L2, L1)
@report_fn_l3
extends match_fn_l3
depends on report
@
identifier K_NO_WAIT =~ "^K_NO_WAIT$";
identifier K_FOREVER =~ "^K_FOREVER$";
position p;
@@
fn@p(...,
(
K_NO_WAIT
|
K_FOREVER
)
, L2, L1)
@script:python
depends on report
@
fn << match_fn_l3.fn;
T << match_fn_l3.T;
p << report_fn_l3.p;
@@
msg = "WARNING: [msl3] replace constant {} with ms duration in {}".format(T, fn)
coccilib.report.print_report(p[0], msg);
@fix_fn_l3
extends match_fn_l3
depends on patch
@
identifier K_NO_WAIT =~ "^K_NO_WAIT$";
identifier K_FOREVER =~ "^K_FOREVER$";
@@
fn(...,
(
- K_NO_WAIT
+ 0
|
- K_FOREVER
+ SYS_FOREVER_MS
)
, L2, L1)