zephyr/scripts
Tomasz Bursztyka 72d9e8c8ab scripts: coccinelle: Scripts for finding wrong device instance usage
2 scripts are provided.
- find_functions.cocci (name probably sucks...)
- find_dev_usage.cocci (ditto...)

find_functions.cocci can patch files where device instance are not
const.

Then it is used to generate the function database:

./scripts/coccicheck --mode=report --jobs=1 \
--cocci=scripts/coccinelle/find_functions.cocci \
--sp-flag="--include-headers" ./

Then, find_dev_usage.cocci will check if the const qualifier is, or
might be lost in a function call.

For instance:
./scripts/coccicheck --mode=report --jobs=1 \
--cocci=scripts/coccinelle/find_dev_usage.cocci \
--sp-flag="--include-headers" drivers/i2c

Which will output a WARNING on non-zephyr functions calls with a device:

./drivers/i2c/i2c_cc13xx_cc26xx.c:393:5-8: WARNING: in i2c_cc13xx_cc26xx_pm_control calling cb param with dev, check if const qualifier is not lost
./drivers/i2c/i2c_mcux_lpi2c.c:205:40-43: WARNING: in mcux_lpi2c_init calling LPI2C_MasterTransferCreateHandle param with dev, check if const qualifier is not lost
./drivers/i2c/i2c_nrfx_twi.c:258:5-8: WARNING: in twi_nrfx_pm_control calling cb param with dev, check if const qualifier is not lost
./drivers/i2c/i2c_nrfx_twi.c:202:22-25: WARNING: in init_twi calling nrfx_twi_init param with dev, check if const qualifier is not lost
./drivers/i2c/i2c_mcux.c:187:38-41: WARNING: in i2c_mcux_init calling I2C_MasterTransferCreateHandle param with dev, check if const qualifier is not lost
./drivers/i2c/i2c_mcux_flexcomm.c:184:43-46: WARNING: in mcux_flexcomm_init calling I2C_MasterTransferCreateHandle param with dev, check if const qualifier is not lost
./drivers/i2c/i2c_nrfx_twim.c:232:5-8: WARNING: in twim_nrfx_pm_control calling cb param with dev, check if const qualifier is not lost
./drivers/i2c/i2c_nrfx_twim.c:174:8-11: WARNING: in init_twim calling nrfx_twim_init param with dev, check if const qualifier is not lost
./drivers/i2c/i2c_rv32m1_lpi2c.c:246:6-9: WARNING: in rv32m1_lpi2c_init calling LPI2C_MasterTransferCreateHandle param with dev, check if const qualifier is not lost

Or:
./scripts/coccicheck --mode=report --jobs=1 \
--cocci=scripts/coccinelle/find_dev_usage.cocci \
--sp-flag="--include-headers" drivers/ieee802154

Which will output an ERROR on using a zephyr function that looses the
const qualifier:

drivers/ieee802154/ieee802154_rf2xx.c:778:3-6: ERROR: in rf2xx_init calling k_thread_create param with dev, loosing const qualifier, please wrap
drivers/ieee802154/ieee802154_nrf5.c:477:19-22: ERROR: in nrf5_init calling k_thread_create param with dev, loosing const qualifier, please wrap
drivers/ieee802154/ieee802154_cc1200.c:819:3-6: ERROR: in cc1200_init calling k_thread_create param with dev, loosing const qualifier, please wrap
drivers/ieee802154/ieee802154_mcr20a.c:1443:3-6: ERROR: in mcr20a_init calling k_thread_create param with dev, loosing const qualifier, please wrap
drivers/ieee802154/ieee802154_cc2520.c:1116:3-6: ERROR: in cc2520_init calling k_thread_create param with dev, loosing const qualifier, please wrap
drivers/ieee802154/ieee802154_cc13xx_cc26xx.c:439:32-35: ERROR: in ieee802154_cc13xx_cc26xx_data_init calling k_thread_create param with dev, loosing const qualifier, please wrap

ISSUE:
- Is it possible to run a set of rules first on all the code, and then
  another set, both sets being in the same .cocci file?
  Would be nice to have all at once.

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
..
checkpatch kernel: rename NANO_ESF 2019-07-25 15:06:58 -07:00
ci ci: do not run sanitycheck on MAINTAINERS.yml changes 2020-08-13 17:03:47 +02:00
coccinelle scripts: coccinelle: Scripts for finding wrong device instance usage 2020-09-02 13:48:13 +02:00
coredump coredump: add support for ARM Cortex-M 2020-08-24 20:28:24 -04:00
dts devicetree: use edt.pickle more 2020-07-23 09:19:45 -05:00
footprint scripts: size_report: fix path prepending 2020-08-14 18:49:26 -04:00
gitlint zephyr_commit_rules.py: Fix pylint warning by simplifying conditional 2019-09-08 22:19:37 -04:00
kconfig hardening: remove the empty line before EOF 2020-08-21 15:09:07 -04:00
net scripts: net: Fix incorrect error messages 2020-05-21 14:45:07 +02:00
release scripts: add script for listing closed bugs 2019-10-22 15:11:09 -04:00
sanity_chk sanitycheck: do not report parent test 2020-09-01 15:02:22 -04:00
support scripts: Simplify code with sys.exit(<string>) 2019-09-08 12:34:16 +02:00
tests sanitycheck: inclusive language 2020-08-27 07:04:07 -04:00
tracing tracing: scripts: add scripts for parsing ctf data 2020-08-24 13:21:12 +02:00
west_commands scripts: west sign: add --quiet option 2020-09-01 13:33:46 +02:00
.gitignore scripts: tests: sanitycheck: Add basic foundation for sanitycheck testsuite 2020-03-24 22:32:26 -04:00
checkpatch.pl scripts: update checkpatch based on current linux kernel version 2020-08-21 13:57:02 -04:00
checkstack.pl First commit 2015-04-10 16:44:37 -07:00
coccicheck scripts: Fix documunt referenc for coccicheck 2020-05-08 17:44:44 +02:00
dir_is_writeable.py global: Remove leading/trailing blank lines in files 2019-12-11 19:17:27 +01:00
file2hex.py scripts: file2hex.py: PEP 8 style fix 2020-06-12 11:09:58 +02:00
filter-known-issues.py filter-known-issues.py: Remove '== True' test 2019-09-08 22:20:20 -04:00
gen_app_partitions.py scripts: Fix random typo'd whitespace 2019-09-07 07:54:17 -04:00
gen_cfb_font_header.py zephyr: replace zephyr integer types with C99 types 2020-06-08 08:23:57 -05:00
gen_gcov_files.py scripts: gen_gcov_files.py: add argument help text 2020-06-13 16:33:22 -04:00
gen_kobject_list.py userspace: update k_object API to support immutable objects 2020-09-02 13:48:13 +02:00
gen_offset_header.py scripts: gen_offset_header: add argument help text 2020-05-21 14:45:24 +02:00
gen_relocate_app.py zephyr: replace zephyr integer types with C99 types 2020-06-08 08:23:57 -05:00
gen_syscalls.py scripts: gen_syscalls: typo fix 2020-06-09 10:39:49 +02:00
get_maintainer.py scripts: add maintainer script 2020-07-24 17:07:48 +02:00
mergehex.py scripts: cmake: move print from python to cmake 2020-01-03 08:20:08 -05:00
parse_syscalls.py userspace: net sockets are kernel objects 2020-06-03 22:33:32 +02:00
process_gperf.py scripts: process_gperf: typo fix 2020-06-09 10:40:58 +02:00
requirements-base.txt requirements: add anytree 2020-08-14 18:49:26 -04:00
requirements-build-test.txt requirements-build-test.txt: Updating mock module version 2020-07-09 06:26:28 -04:00
requirements-compliance.txt python3: add check_compliance package requirements 2020-08-11 14:49:48 -04:00
requirements-doc.txt doc: update versions of build tools 2020-08-31 09:57:33 -04:00
requirements-extras.txt scripts/requirements: add lpc_checksum script 2020-07-29 20:12:24 +02:00
requirements-run-test.txt requirements: add psutil, needed by sanitycheck 2020-05-06 11:07:22 -05:00
requirements.txt python3: add check_compliance package requirements 2020-08-11 14:49:48 -04:00
sanitycheck sanitycheck: add argument --pre-script 2020-08-31 15:54:32 +02:00
series-push-hook.sh scripts: fix path issue in push-hook script 2019-03-13 11:59:38 -05:00
spelling.txt scripts: updated spelling.txt file 2017-07-14 12:57:40 +03:00
subfolder_list.py scripts: subfolder_list.py: refactor the code 2020-07-20 17:31:53 -04:00
tags.sh scripts: fix tags.sh to current source tree 2018-01-15 18:30:28 -05:00
user_wordsize.py posix arch: build on aarch64 / allow host-specific cmake includes 2020-05-09 12:17:24 +02:00
valgrind.supp lvgl: Suppress memory leak errors detected by valgrind 2019-10-21 12:26:35 -07:00
west-commands.yml cmake: West extension command for Zephyr config package registration 2020-03-27 16:23:46 +01:00
zephyr_module.py cmake: zephyr module processing improvements. 2020-08-31 12:15:02 +02:00