1// Copyright (c) 2019-2020 Nordic Semiconductor ASA 2// SPDX-License-Identifier: Apache-2.0 3 4// Replace use of K_NO_WAIT and K_FOREVER in API that requires 5// timeouts be specified as integral milliseconds. 6// 7// These constants used to have the values 0 and -1 respectively; they 8// are now timeout values which are opaque non-integral values that 9// can't be converted to integers automatically. For K_NO_WAIT replace 10// with 0; for K_FOREVER replace with SYS_FOREVER_MS, the value of 11// which is -1. 12// 13// Options: --include-headers 14 15virtual patch 16virtual report 17 18// ** Handle millisecond timeout as the last parameter 19 20// Match identifier passed as timeout 21@match_fn_l1@ 22identifier fn =~ "(?x)^ 23(dmic_read 24|bt_buf_get_(rx|cmd_complete|evt) 25|bt_mesh_cfg_cli_timeout_set 26|isotp_(bind|recv(_net)?|send(_net)?(_ctx)?_buf) 27|tty_set_(tx|rx)_timeout 28|can_(write|recover) 29|uart_(tx|rx_enable) 30|dns_(resolve_name|get_addr_info) 31|net_config_init 32|net_ppp_ping 33|websocket_(send|recv)_msg 34)$"; 35identifier T; 36@@ 37 fn(..., T); 38 39@report_fn_l1 40 extends match_fn_l1 41 depends on report 42@ 43identifier K_NO_WAIT =~ "^K_NO_WAIT$"; 44identifier K_FOREVER =~ "^K_FOREVER$"; 45position p; 46@@ 47 fn@p(..., 48( 49K_NO_WAIT 50| 51K_FOREVER 52) 53 ) 54 55@script:python 56 depends on report 57@ 58fn << match_fn_l1.fn; 59T << match_fn_l1.T; 60p << report_fn_l1.p; 61@@ 62msg = "WARNING: [msl1] replace constant {} with ms duration in {}".format(T, fn) 63coccilib.report.print_report(p[0], msg); 64 65@fix_fn_l1 66 extends match_fn_l1 67 depends on patch 68@ 69identifier K_NO_WAIT =~ "^K_NO_WAIT$"; 70identifier K_FOREVER =~ "^K_FOREVER$"; 71@@ 72 fn(..., 73( 74- K_NO_WAIT 75+ 0 76| 77- K_FOREVER 78+ SYS_FOREVER_MS 79)) 80 81// ** Handle millisecond timeout as second from last parameter 82 83// Match identifier passed as timeout 84@match_fn_l2@ 85identifier fn =~ "(?x)^ 86(http_client_req 87|websocket_connect 88)$"; 89expression L1; 90identifier T; 91@@ 92 fn(..., T, L1) 93 94@report_fn_l2 95 extends match_fn_l2 96 depends on report 97@ 98identifier K_NO_WAIT =~ "^K_NO_WAIT$"; 99identifier K_FOREVER =~ "^K_FOREVER$"; 100expression X1; 101position p; 102@@ 103 fn@p(..., 104( 105K_NO_WAIT 106| 107K_FOREVER 108) 109 , X1) 110 111@script:python 112 depends on report 113@ 114fn << match_fn_l2.fn; 115T << match_fn_l2.T; 116p << report_fn_l2.p; 117@@ 118msg = "WARNING: [msl2] replace constant {} with ms duration in {}".format(T, fn) 119coccilib.report.print_report(p[0], msg); 120 121@fix_fn_l2 122 extends match_fn_l2 123 depends on patch 124@ 125identifier K_NO_WAIT =~ "^K_NO_WAIT$"; 126identifier K_FOREVER =~ "^K_FOREVER$"; 127expression X1; 128@@ 129 fn(..., 130( 131- K_NO_WAIT 132+ 0 133| 134- K_FOREVER 135+ SYS_FOREVER_MS 136) 137 , X1) 138 139// ** Handle millisecond timeout as third from last parameter 140 141// Match identifier passed as timeout 142@match_fn_l3@ 143identifier fn =~ "(?x)^ 144(can_send 145|lora_recv 146)$"; 147expression L1; 148expression L2; 149identifier T; 150@@ 151 fn(..., T, L2, L1) 152 153@report_fn_l3 154 extends match_fn_l3 155 depends on report 156@ 157identifier K_NO_WAIT =~ "^K_NO_WAIT$"; 158identifier K_FOREVER =~ "^K_FOREVER$"; 159position p; 160@@ 161 fn@p(..., 162( 163K_NO_WAIT 164| 165K_FOREVER 166) 167 , L2, L1) 168 169@script:python 170 depends on report 171@ 172fn << match_fn_l3.fn; 173T << match_fn_l3.T; 174p << report_fn_l3.p; 175@@ 176msg = "WARNING: [msl3] replace constant {} with ms duration in {}".format(T, fn) 177coccilib.report.print_report(p[0], msg); 178 179@fix_fn_l3 180 extends match_fn_l3 181 depends on patch 182@ 183identifier K_NO_WAIT =~ "^K_NO_WAIT$"; 184identifier K_FOREVER =~ "^K_FOREVER$"; 185@@ 186 fn(..., 187( 188- K_NO_WAIT 189+ 0 190| 191- K_FOREVER 192+ SYS_FOREVER_MS 193) 194 , L2, L1) 195