From 667eeb11fbd7dd87eb68e3e78dad191152d1b7e0 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 13 Apr 2023 18:59:37 +0200 Subject: [PATCH] shell: fix MISRA 5.7 violations on `struct shell` MISRA Rule 5.7 requires uniqueness of tag identifiers. Shell is frequently problematic because many code uses `const struct shell *shell`. This causes CI noise every time one of these shell files is edited, so let's update all of them with `const struct shell *sh` instead. Signed-off-by: Gerard Marull-Paretas --- doc/services/shell/index.rst | 30 +- drivers/adc/adc_shell.c | 48 +- drivers/clock_control/clock_control_nrf.c | 14 +- drivers/dac/dac_shell.c | 12 +- drivers/edac/shell.c | 114 +-- drivers/eeprom/eeprom_shell.c | 56 +- drivers/flash/flash_shell.c | 72 +- drivers/led/led_shell.c | 102 +-- drivers/lora/shell.c | 98 +-- drivers/modem/modem_shell.c | 42 +- drivers/pwm/pwm_shell.c | 18 +- drivers/sensor/sensor_shell.c | 12 +- drivers/sensor/shell_battery.c | 38 +- drivers/virtualization/virt_ivshmem_shell.c | 50 +- drivers/wifi/eswifi/eswifi_shell.c | 10 +- include/zephyr/shell/shell.h | 94 +-- include/zephyr/shell/shell_dummy.h | 8 +- lib/posix/getopt/README | 2 +- modules/openthread/platform/shell.c | 6 +- samples/arch/mpu/mpu_test/src/main.c | 34 +- samples/drivers/flash_shell/src/main.c | 174 ++-- samples/net/gsm_modem/src/main.c | 8 +- samples/net/promiscuous_mode/src/main.c | 20 +- .../net/sockets/echo_server/src/echo-server.c | 2 +- samples/net/sockets/txtime/src/main.c | 2 +- .../shell/shell_module/src/dynamic_cmd.c | 32 +- samples/subsys/shell/shell_module/src/main.c | 64 +- .../shell/shell_module/src/uart_reinit.c | 12 +- subsys/bluetooth/mesh/shell/utils.h | 6 +- .../coredump_backend_flash_partition.c | 78 +- .../debug/coredump/coredump_backend_logging.c | 10 +- subsys/dfu/boot/mcuboot_shell.c | 44 +- subsys/fb/cfb_shell.c | 146 ++-- subsys/fs/shell.c | 98 +-- subsys/logging/log_cmds.c | 100 +-- subsys/mgmt/hawkbit/shell.c | 28 +- .../mcumgr/grp/shell_mgmt/src/shell_mgmt.c | 6 +- subsys/mgmt/updatehub/shell.c | 20 +- subsys/net/l2/bluetooth/bluetooth_shell.c | 32 +- subsys/net/l2/ieee802154/ieee802154_shell.c | 134 ++-- subsys/shell/backends/shell_dummy.c | 8 +- subsys/shell/modules/date_service.c | 44 +- subsys/shell/modules/device_service.c | 6 +- subsys/shell/modules/kernel_service.c | 62 +- subsys/shell/shell.c | 744 +++++++++--------- subsys/shell/shell_cmds.c | 134 ++-- subsys/shell/shell_fprintf.c | 6 +- subsys/shell/shell_help.c | 56 +- subsys/shell/shell_help.h | 4 +- subsys/shell/shell_ops.c | 320 ++++---- subsys/shell/shell_ops.h | 4 +- subsys/shell/shell_utils.c | 6 +- subsys/shell/shell_utils.h | 12 +- subsys/shell/shell_wildcard.c | 40 +- subsys/shell/shell_wildcard.h | 6 +- subsys/storage/flash_map/flash_map_shell.c | 8 +- subsys/testsuite/include/zephyr/tc_util.h | 2 +- tests/bluetooth/shell/src/main.c | 18 +- tests/subsys/shell/shell/src/main.c | 56 +- .../shell/shell_flash/src/shell_flash_test.c | 4 +- 60 files changed, 1708 insertions(+), 1708 deletions(-) diff --git a/doc/services/shell/index.rst b/doc/services/shell/index.rst index 209bdab320..6cdb0020bf 100644 --- a/doc/services/shell/index.rst +++ b/doc/services/shell/index.rst @@ -163,7 +163,7 @@ Abstract code for this task would look like this: .. code-block:: c - static int gain_cmd_handler(const struct shell *shell, + static int gain_cmd_handler(const struct shell *sh, size_t argc, char **argv, void *data) { int gain; @@ -172,7 +172,7 @@ Abstract code for this task would look like this: gain = (int)data; adc_set_gain(gain); - shell_print(shell, "ADC gain set to: %s\n" + shell_print(sh, "ADC gain set to: %s\n" "Value send to ADC driver: %d", argv[0], gain); @@ -332,7 +332,7 @@ Simple command handler implementation: .. code-block:: c - static int cmd_handler(const struct shell *shell, size_t argc, + static int cmd_handler(const struct shell *sh, size_t argc, char **argv) { ARG_UNUSED(argc); @@ -340,11 +340,11 @@ Simple command handler implementation: shell_fprintf(shell, SHELL_INFO, "Print info message\n"); - shell_print(shell, "Print simple text."); + shell_print(sh, "Print simple text."); - shell_warn(shell, "Print warning text."); + shell_warn(sh, "Print warning text."); - shell_error(shell, "Print error text."); + shell_error(sh, "Print error text."); return 0; } @@ -379,7 +379,7 @@ commands or the parent commands, depending on how you index ``argv``. .. code-block:: c - static int cmd_handler(const struct shell *shell, size_t argc, + static int cmd_handler(const struct shell *sh, size_t argc, char **argv) { ARG_UNUSED(argc); @@ -387,14 +387,14 @@ commands or the parent commands, depending on how you index ``argv``. /* If it is a subcommand handler parent command syntax * can be found using argv[-1]. */ - shell_print(shell, "This command has a parent command: %s", + shell_print(sh, "This command has a parent command: %s", argv[-1]); /* Print this command syntax */ - shell_print(shell, "This command syntax is: %s", argv[0]); + shell_print(sh, "This command syntax is: %s", argv[0]); /* Print first argument */ - shell_print(shell, "%s", argv[1]); + shell_print(sh, "%s", argv[1]); return 0; } @@ -665,24 +665,24 @@ The following code shows a simple use case of this library: } - static int cmd_demo_ping(const struct shell *shell, size_t argc, + static int cmd_demo_ping(const struct shell *sh, size_t argc, char **argv) { ARG_UNUSED(argc); ARG_UNUSED(argv); - shell_print(shell, "pong"); + shell_print(sh, "pong"); return 0; } - static int cmd_demo_params(const struct shell *shell, size_t argc, + static int cmd_demo_params(const struct shell *sh, size_t argc, char **argv) { int cnt; - shell_print(shell, "argc = %d", argc); + shell_print(sh, "argc = %d", argc); for (cnt = 0; cnt < argc; cnt++) { - shell_print(shell, " argv[%d] = %s", cnt, argv[cnt]); + shell_print(sh, " argv[%d] = %s", cnt, argv[cnt]); } return 0; } diff --git a/drivers/adc/adc_shell.c b/drivers/adc/adc_shell.c index 0aa07ce550..c86362327a 100644 --- a/drivers/adc/adc_shell.c +++ b/drivers/adc/adc_shell.c @@ -124,19 +124,19 @@ static struct adc_hdl *get_adc(const char *device_label) return NULL; } -static int cmd_adc_ch_id(const struct shell *shell, size_t argc, char **argv) +static int cmd_adc_ch_id(const struct shell *sh, size_t argc, char **argv) { /* -2: index of ADC label name */ struct adc_hdl *adc = get_adc(argv[-2]); int retval = 0; if (!device_is_ready(adc->dev)) { - shell_error(shell, "ADC device not ready"); + shell_error(sh, "ADC device not ready"); return -ENODEV; } if (isdigit((unsigned char)argv[1][0]) == 0) { - shell_error(shell, " must be digits"); + shell_error(sh, " must be digits"); return -EINVAL; } @@ -147,7 +147,7 @@ static int cmd_adc_ch_id(const struct shell *shell, size_t argc, char **argv) return retval; } -static int cmd_adc_ch_neg(const struct shell *shell, size_t argc, char **argv) +static int cmd_adc_ch_neg(const struct shell *sh, size_t argc, char **argv) { #if CONFIG_ADC_CONFIGURABLE_INPUTS /* -2: index of ADC label name */ @@ -155,12 +155,12 @@ static int cmd_adc_ch_neg(const struct shell *shell, size_t argc, char **argv) int retval = 0; if (!device_is_ready(adc->dev)) { - shell_error(shell, "ADC device not ready"); + shell_error(sh, "ADC device not ready"); return -ENODEV; } if (isdigit((unsigned char)argv[1][0]) == 0) { - shell_error(shell, " must be digits"); + shell_error(sh, " must be digits"); return -EINVAL; } @@ -174,7 +174,7 @@ static int cmd_adc_ch_neg(const struct shell *shell, size_t argc, char **argv) #endif } -static int cmd_adc_ch_pos(const struct shell *shell, size_t argc, char **argv) +static int cmd_adc_ch_pos(const struct shell *sh, size_t argc, char **argv) { #if CONFIG_ADC_CONFIGURABLE_INPUTS /* -2: index of ADC label name */ @@ -182,12 +182,12 @@ static int cmd_adc_ch_pos(const struct shell *shell, size_t argc, char **argv) int retval = 0; if (!device_is_ready(adc->dev)) { - shell_error(shell, "ADC device not ready"); + shell_error(sh, "ADC device not ready"); return -ENODEV; } if (isdigit((unsigned char)argv[1][0]) == 0) { - shell_error(shell, " must be digits"); + shell_error(sh, " must be digits"); return -EINVAL; } @@ -201,7 +201,7 @@ static int cmd_adc_ch_pos(const struct shell *shell, size_t argc, char **argv) #endif } -static int cmd_adc_gain(const struct shell *shell, size_t argc, char **argv, +static int cmd_adc_gain(const struct shell *sh, size_t argc, char **argv, void *data) { /* -2: index of ADC label name */ @@ -210,7 +210,7 @@ static int cmd_adc_gain(const struct shell *shell, size_t argc, char **argv, int retval = -EINVAL; if (!device_is_ready(adc->dev)) { - shell_error(shell, "ADC device not ready"); + shell_error(sh, "ADC device not ready"); return -ENODEV; } @@ -225,7 +225,7 @@ static int cmd_adc_gain(const struct shell *shell, size_t argc, char **argv, return retval; } -static int cmd_adc_acq(const struct shell *shell, size_t argc, char **argv) +static int cmd_adc_acq(const struct shell *sh, size_t argc, char **argv) { /* -1 index of ADC label name */ struct adc_hdl *adc = get_adc(argv[-1]); @@ -233,12 +233,12 @@ static int cmd_adc_acq(const struct shell *shell, size_t argc, char **argv) int retval; if (!device_is_ready(adc->dev)) { - shell_error(shell, "ADC device not ready"); + shell_error(sh, "ADC device not ready"); return -ENODEV; } if (isdigit((unsigned char)argv[1][0]) == 0) { - shell_error(shell, "