Skip to content

Commit

Permalink
drivers: gpio: shell: Fixed gpio info crash bug
Browse files Browse the repository at this point in the history
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 <andy.sinclair@nordicsemi.no>
  • Loading branch information
aasinclair authored and aescolar committed Jun 20, 2024
1 parent 1198c7e commit 7f0f0a4
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions drivers/gpio/gpio_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,21 +530,22 @@ static void print_gpio_ctrl_info(const struct shell *sh, const struct gpio_ctrl
{
gpio_pin_t pin;
bool reserved;
const char *line_name;

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

shell_print(sh, "");

shell_print(sh, " Reserved Pin Line Name");
for (pin = 0; pin < GPIO_MAX_PINS_PER_PORT; pin++) {
if ((pin >= ctrl->ngpios) && (pin >= ctrl->line_names_len)) {
/* Out of info */
break;
}
for (pin = 0; pin < ctrl->ngpios; pin++) {
reserved = (BIT64(pin) & ctrl->reserved_mask) != 0;
shell_print(sh, " %c %2u %s", reserved ? '*' : ' ',
pin, ctrl->line_names[pin]);
if (pin < ctrl->line_names_len) {
line_name = ctrl->line_names[pin];
} else {
line_name = "";
}
shell_print(sh, " %c %2u %s", reserved ? '*' : ' ', pin, line_name);
}
}

Expand Down

0 comments on commit 7f0f0a4

Please sign in to comment.