scripts/coccinelle: improve int_literal_to_timeout
Replace timeout parameters that are multiples of MSEC_PER_SEC, or such a value passed through K_MSEC, with the normalized timeout expression using whole seconds. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
parent
9d29e1c48c
commit
d4bb09c083
1 changed files with 82 additions and 1 deletions
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
// Copyright (c) 2019-2020 Nordic Semiconductor ASA
|
||||
// SPDX-License-Identifer: Apache-2.0
|
||||
|
||||
// Replace integer constant timeouts with K_MSEC variants
|
||||
|
@ -8,6 +8,9 @@
|
|||
// produced by specific constants and macros. Convert the integer
|
||||
// literals to the desired equivalent.
|
||||
//
|
||||
// A few expressions that are clearly integer values are also
|
||||
// converted.
|
||||
//
|
||||
// Options: --include-headers
|
||||
|
||||
virtual patch
|
||||
|
@ -88,6 +91,84 @@ C << r_last_timeout_const_report.C;
|
|||
msg = "WARNING: replace constant {} with timeout in {}".format(C, fn)
|
||||
coccilib.report.print_report(p[0], msg);
|
||||
|
||||
// ** Handle call sites where a timeout is specified by an expression
|
||||
// ** scaled by MSEC_PER_SEC and replace with the corresponding
|
||||
// ** K_SECONDS() expression.
|
||||
|
||||
@r_last_timeout_scaled_patch
|
||||
extends r_last_timeout
|
||||
depends on patch
|
||||
@
|
||||
// identifier K_MSEC =~ "^K_MSEC$";
|
||||
symbol K_MSEC;
|
||||
identifier MSEC_PER_SEC =~ "^MSEC_PER_SEC$";
|
||||
expression V;
|
||||
position p;
|
||||
@@
|
||||
last_timeout@p(...,
|
||||
(
|
||||
- MSEC_PER_SEC
|
||||
+ K_SECONDS(1)
|
||||
|
|
||||
- V * MSEC_PER_SEC
|
||||
+ K_SECONDS(V)
|
||||
|
|
||||
- K_MSEC(MSEC_PER_SEC)
|
||||
+ K_SECONDS(1)
|
||||
|
|
||||
- K_MSEC(V * MSEC_PER_SEC)
|
||||
+ K_SECONDS(V)
|
||||
)
|
||||
)
|
||||
|
||||
@r_last_timeout_scaled_report_req
|
||||
extends r_last_timeout
|
||||
depends on report
|
||||
@
|
||||
identifier MSEC_PER_SEC =~ "^MSEC_PER_SEC$";
|
||||
expression V;
|
||||
position p;
|
||||
@@
|
||||
last_timeout@p(...,
|
||||
(
|
||||
MSEC_PER_SEC
|
||||
| V * MSEC_PER_SEC
|
||||
)
|
||||
)
|
||||
|
||||
@r_last_timeout_scaled_report_opt
|
||||
extends r_last_timeout
|
||||
depends on report
|
||||
@
|
||||
identifier MSEC_PER_SEC =~ "^MSEC_PER_SEC$";
|
||||
expression V;
|
||||
position p;
|
||||
@@
|
||||
last_timeout@p(...,
|
||||
(
|
||||
K_MSEC(MSEC_PER_SEC)
|
||||
| K_MSEC(V * MSEC_PER_SEC)
|
||||
)
|
||||
)
|
||||
|
||||
@script:python
|
||||
depends on report
|
||||
@
|
||||
fn << r_last_timeout.last_timeout;
|
||||
p << r_last_timeout_scaled_report_req.p;
|
||||
@@
|
||||
msg = "WARNING: use K_SECONDS() for timeout in {}".format(fn)
|
||||
coccilib.report.print_report(p[0], msg);
|
||||
|
||||
@script:python
|
||||
depends on report
|
||||
@
|
||||
fn << r_last_timeout.last_timeout;
|
||||
p << r_last_timeout_scaled_report_opt.p;
|
||||
@@
|
||||
msg = "NOTE: use K_SECONDS() for timeout in {}".format(fn)
|
||||
coccilib.report.print_report(p[0], msg);
|
||||
|
||||
// ** Convert timeout-valued delays in K_THREAD_DEFINE with durations
|
||||
// ** in milliseconds
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue