k_thread_create and K_THREAD_DEFINE both take a delay as the final
parameter. Most uses of K_THREAD_DEFINE pass either `K_NO_WAIT` or
`K_FOREVER`. Ensure that all uses of K_THREAD_DEFINE follow that
practice, and that the runtime k_thread_create calls do so as well.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
k_sleep uses the same underlying thread infrastructure as the other
functions that take timeouts, so the delay should be specified as a
timeout rather than milliseconds.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Sort the functions within the regular expression so they can be
checked more easily.
Remove k_thread_deadline_set as it takes an argument in cycles. (The
one in-tree call to this function was not affected by this error.)
Add missed k_mbox_data_block_get.
Fix an overly ambitious multi-match disjunct that covered some
non-existent functions.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Add support for the report and patch modes so this can be invoked by
coccicheck.
Use PCRE options to make the kernel timeout API identifier rule more
readable. Extend the pattern to new API.
Use rule extends and depends clauses, and pattern disjunction, to
avoid replicating metavariable content.
Hint that using --include-headers may be helpful (some patterns can be
found in static inline functions).
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Some legacy code still passes integer literals in milliseconds as the
value to functions that take a timeout. This usage interferes with
plans to replace the millisecond representation with a more generic
k_timeout_t value. Add a Coccinelle script to convert call sites to
use the proper constants and macros.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Add a simple Coccinelle script that counts identifier lengths and
prints out a warning if it is longer than 31 characters.
The script can be run with:
spatch -D report --very-quiet \
--include-headers --recursive-includes \
--cocci-file $ZEPHYR_BASE/scripts/coccinelle/identifier_length.cocci \
--dir $ZEPHYR_BASE \
kernel/
Where '--include-headers' and '--recursive-includes' can be omitted
if neede.
Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
Update the script to detect and update more instances of unsigned
variable assignments when using all four simple rules of arithmetics.
Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
The return of memcpy was being ignored just like memset's return. Just
adding it to coccinelle script.
MISRA-C rule 17.7
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Add a Coccinelle script that adds an 'U' to values assigned to
unsigned variables, according ot MISRA-C rule 7.2.
Add a 'report' mode to the script that can be used by developer/CI
and a 'patch' mode that should do the heavy lifting.
Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
This script helps to remove bogus intermediate local variable
used in functions to store return value and instead return
directly while saving few bits of memory.
Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
The following addition `depends on !(file in "ext")` allows
to exclude `ext/` warnings reported by coccinelle scripts.
Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
sizeof when applied to a pointer typed expression gives the size of
the pointer and not the size of the object associated with the pointer
expression leading to errors.
This scripts checks for inconsistencies where sizeof is incorrectly
used, especially while calculating size of memory to be allocated in
memory allocating functions.
Eg:
- memset(pStr, 0, sizeof(pStr));
+ memset(pStr, 0, sizeof(*pStr));
Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
This script allowes to remove the redundant semicolon from
`if`, `switch`, `while`, `for` statements.
Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
Unsigned expressions cannot be less than zero and presence
of such practices very likely indicates a bug.
Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
This script finds cases of missing locks in the code.
There is some possibilty of false positives in cases
where a particular function is supposed to exit with
the lock held or there is any preceding function call
that releases the lock.
Suggested-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
* Provide a single liner description at top using `///`
comments. This one liner is displayed when using `--verbose`
mode of coccicheck.
* Specify Condidence level property adhering to coccinelle.rst
section "Proposing new semantic patches".
* Add virtual patch rule to handle the patch case when coccicheck
is supplied with `--mode=patch` option.
* Add `depends on !(file in "ext")` to ignore reports from `ext/`
directory.
* Simplify rule to use disjunctions and use "exists" to match any
available control path.
Suggested-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
* Provide a single liner description at top using `///`
comments. This one liner is displayed when using `--verbose`
mode of coccicheck.
* Specify Condidence level property adhering to coccinelle.rst
section "Proposing new semantic patches".
* Add virtual patch rule to handle the patch case when coccicheck
is supplied with `--mode=patch` option.
* Add `depends on !(file in "ext")` to ignore reports from `ext/`
directory.
* Simplify patch rule to reduce effort in reconstruction since
logically we are only *adding* void cast.
Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
This script finds cases of NULL dereferences where a variable
is dereferenced under a NULL test, even though it is known
to be NULL.
Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
* Use `expression` metavariable instead of `constant` to catch
missing cases such as:
diff -u -p a/subsys/net/ip/rpl.c b/subsys/net/ip/rpl.c
--- a/subsys/net/ip/rpl.c
+++ b/subsys/net/ip/rpl.c
@@ -686,7 +686,7 @@ static void new_dio_interval(struct net_
{
u32_t time;
- time = 1 << instance->dio_interval_current;
+ time = BIT(instance->dio_interval_current);
* Provide a single liner description at top using `///`
comments. This one liner is displayed when using `--verbose`
mode of coccicheck.
* Specify Condidence level property adhering to coccinelle.rst
section "Proposing new semantic patches".
* Add virtual patch rule to handle the patch case when coccicheck
is supplied with `--mode=patch` option.
* Edit patch rule to remove redundant parentheses in the output.
* Add `depends on !(file in "ext")` to ignore reports from `ext/`
directory.
Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
This script detects cases where ARRAY_SIZE can be used such as
where there is a division of sizeof the array by the sizeof its first
element or by any indexed element or the element type. It replaces the
division of the two sizeofs by ARRAY_SIZE helper macro.
Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
The return of memset is never checked. This patch explicitly ignore
the return to avoid MISRA-C violations.
The only directory excluded directory was ext/* since it contains
only imported code.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Bitwise operators should be used only with unsigned integer operands
because the result os bitwise operations on signed integers are
implementation-defined.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
irq_lock returns an unsigned int, though, several places was using
signed int. This commit fix this behaviour.
In order to avoid this error happens again, a coccinelle script was
added and can be used to check violations.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>