Skip to content

Commit

Permalink
shell: fix MISRA 5.7 violations on struct shell
Browse files Browse the repository at this point in the history
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 <gerard.marull@nordicsemi.no>
  • Loading branch information
gmarull authored and carlescufi committed Apr 14, 2023
1 parent c7c8ea6 commit 667eeb1
Show file tree
Hide file tree
Showing 60 changed files with 1,708 additions and 1,708 deletions.
30 changes: 15 additions & 15 deletions doc/services/shell/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -332,19 +332,19 @@ 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);
ARG_UNUSED(argv);
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;
}
Expand Down Expand Up @@ -379,22 +379,22 @@ 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);
/* 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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
48 changes: 24 additions & 24 deletions drivers/adc/adc_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<channel> must be digits");
shell_error(sh, "<channel> must be digits");
return -EINVAL;
}

Expand All @@ -147,20 +147,20 @@ 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 */
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, "<negative input> must be digits");
shell_error(sh, "<negative input> must be digits");
return -EINVAL;
}

Expand All @@ -174,20 +174,20 @@ 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 */
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, "<positive input> must be digits");
shell_error(sh, "<positive input> must be digits");
return -EINVAL;
}

Expand All @@ -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 */
Expand All @@ -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;
}

Expand All @@ -225,20 +225,20 @@ 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]);
uint16_t acq_time;
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, "<time> must be digits");
shell_error(sh, "<time> must be digits");
return -EINVAL;
}

Expand All @@ -261,19 +261,19 @@ static int cmd_adc_acq(const struct shell *shell, size_t argc, char **argv)

return retval;
}
static int cmd_adc_reso(const struct shell *shell, size_t argc, char **argv)
static int cmd_adc_reso(const struct shell *sh, size_t argc, char **argv)
{
/* -1 index of ADC label name */
struct adc_hdl *adc = get_adc(argv[-1]);
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, "<resolution> must be digits");
shell_error(sh, "<resolution> must be digits");
return -EINVAL;
}

Expand All @@ -283,7 +283,7 @@ static int cmd_adc_reso(const struct shell *shell, size_t argc, char **argv)
return retval;
}

static int cmd_adc_ref(const struct shell *shell, size_t argc, char **argv,
static int cmd_adc_ref(const struct shell *sh, size_t argc, char **argv,
void *data)
{
/* -2 index of ADC label name */
Expand All @@ -292,7 +292,7 @@ static int cmd_adc_ref(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;
}

Expand All @@ -309,7 +309,7 @@ static int cmd_adc_ref(const struct shell *shell, size_t argc, char **argv,
}

#define BUFFER_SIZE 1
static int cmd_adc_read(const struct shell *shell, size_t argc, char **argv)
static int cmd_adc_read(const struct shell *sh, size_t argc, char **argv)
{
uint8_t adc_channel_id = strtol(argv[1], NULL, 10);
/* -1 index of adc label name */
Expand All @@ -318,7 +318,7 @@ static int cmd_adc_read(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;
}

Expand All @@ -332,18 +332,18 @@ static int cmd_adc_read(const struct shell *shell, size_t argc, char **argv)

retval = adc_read(adc->dev, &sequence);
if (retval >= 0) {
shell_print(shell, "read: %i", m_sample_buffer[0]);
shell_print(sh, "read: %i", m_sample_buffer[0]);
}

return retval;
}

static int cmd_adc_print(const struct shell *shell, size_t argc, char **argv)
static int cmd_adc_print(const struct shell *sh, size_t argc, char **argv)
{
/* -1 index of ADC label name */
struct adc_hdl *adc = get_adc(argv[-1]);

shell_print(shell, "%s:\n"
shell_print(sh, "%s:\n"
"Gain: %s\n"
"Reference: %s\n"
"Acquisition Time: %u\n"
Expand Down
14 changes: 7 additions & 7 deletions drivers/clock_control/clock_control_nrf.c
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ DEVICE_DT_DEFINE(DT_NODELABEL(clock), clk_init, NULL,
PRE_KERNEL_1, CONFIG_CLOCK_CONTROL_INIT_PRIORITY,
&clock_control_api);

static int cmd_status(const struct shell *shell, size_t argc, char **argv)
static int cmd_status(const struct shell *sh, size_t argc, char **argv)
{
nrf_clock_hfclk_t hfclk_src;
bool hf_status;
Expand All @@ -757,15 +757,15 @@ static int cmd_status(const struct shell *shell, size_t argc, char **argv)
abs_stop = hf_stop_tstamp;
irq_unlock(key);

shell_print(shell, "HF clock:");
shell_print(shell, "\t- %srunning (users: %u)",
shell_print(sh, "HF clock:");
shell_print(sh, "\t- %srunning (users: %u)",
hf_status ? "" : "not ", hf_mgr->refs);
shell_print(shell, "\t- last start: %u ms (%u ms ago)",
shell_print(sh, "\t- last start: %u ms (%u ms ago)",
(uint32_t)abs_start, (uint32_t)(now - abs_start));
shell_print(shell, "\t- last stop: %u ms (%u ms ago)",
shell_print(sh, "\t- last stop: %u ms (%u ms ago)",
(uint32_t)abs_stop, (uint32_t)(now - abs_stop));
shell_print(shell, "LF clock:");
shell_print(shell, "\t- %srunning (users: %u)",
shell_print(sh, "LF clock:");
shell_print(sh, "\t- %srunning (users: %u)",
lf_status ? "" : "not ", lf_mgr->refs);

return 0;
Expand Down
12 changes: 6 additions & 6 deletions drivers/dac/dac_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ static const struct args_index args_indx = {
.resolution = 3,
};

static int cmd_setup(const struct shell *shell, size_t argc, char **argv)
static int cmd_setup(const struct shell *sh, size_t argc, char **argv)
{
struct dac_channel_cfg cfg;
const struct device *dac;
int err;

dac = device_get_binding(argv[args_indx.device]);
if (!dac) {
shell_error(shell, "DAC device not found");
shell_error(sh, "DAC device not found");
return -EINVAL;
}

Expand All @@ -44,14 +44,14 @@ static int cmd_setup(const struct shell *shell, size_t argc, char **argv)

err = dac_channel_setup(dac, &cfg);
if (err) {
shell_error(shell, "Failed to setup DAC channel (err %d)", err);
shell_error(sh, "Failed to setup DAC channel (err %d)", err);
return err;
}

return 0;
}

static int cmd_write_value(const struct shell *shell, size_t argc, char **argv)
static int cmd_write_value(const struct shell *sh, size_t argc, char **argv)
{
const struct device *dac;
uint8_t channel;
Expand All @@ -60,7 +60,7 @@ static int cmd_write_value(const struct shell *shell, size_t argc, char **argv)

dac = device_get_binding(argv[args_indx.device]);
if (!dac) {
shell_error(shell, "DAC device not found");
shell_error(sh, "DAC device not found");
return -EINVAL;
}

Expand All @@ -69,7 +69,7 @@ static int cmd_write_value(const struct shell *shell, size_t argc, char **argv)

err = dac_write_value(dac, channel, value);
if (err) {
shell_error(shell, "Failed to write DAC value (err %d)", err);
shell_error(sh, "Failed to write DAC value (err %d)", err);
return err;
}

Expand Down
Loading

0 comments on commit 667eeb1

Please sign in to comment.