Skip to content

Commit 7f0f0a4

Browse files
aasinclairaescolar
authored andcommitted
drivers: gpio: shell: Fixed gpio info crash bug
When getting gpio info for a specific device with no line names, invalid memory was accessed. The check for the length of the line name array has been corrected to avoid this. Signed-off-by: Andy Sinclair <[email protected]>
1 parent 1198c7e commit 7f0f0a4

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

drivers/gpio/gpio_shell.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -530,21 +530,22 @@ static void print_gpio_ctrl_info(const struct shell *sh, const struct gpio_ctrl
530530
{
531531
gpio_pin_t pin;
532532
bool reserved;
533+
const char *line_name;
533534

534535
shell_print(sh, " ngpios: %u", ctrl->ngpios);
535536
shell_print(sh, " Reserved pin mask: 0x%08X", ctrl->reserved_mask);
536537

537538
shell_print(sh, "");
538539

539540
shell_print(sh, " Reserved Pin Line Name");
540-
for (pin = 0; pin < GPIO_MAX_PINS_PER_PORT; pin++) {
541-
if ((pin >= ctrl->ngpios) && (pin >= ctrl->line_names_len)) {
542-
/* Out of info */
543-
break;
544-
}
541+
for (pin = 0; pin < ctrl->ngpios; pin++) {
545542
reserved = (BIT64(pin) & ctrl->reserved_mask) != 0;
546-
shell_print(sh, " %c %2u %s", reserved ? '*' : ' ',
547-
pin, ctrl->line_names[pin]);
543+
if (pin < ctrl->line_names_len) {
544+
line_name = ctrl->line_names[pin];
545+
} else {
546+
line_name = "";
547+
}
548+
shell_print(sh, " %c %2u %s", reserved ? '*' : ' ', pin, line_name);
548549
}
549550
}
550551

0 commit comments

Comments
 (0)