Skip to content

Commit

Permalink
drivers: pinctrl: fix lookup when there are no states
Browse files Browse the repository at this point in the history
Right now it is possible that some devices define 0 pinctrl states in
devicetree, because pinctrl-N entries may still be optional for backward
compatibility. If the programmer makes a mistake and forgets them,
application could experience runtime crashes because
pinctrl_lookup_states assumes you have at least one state, so it does
not perform any bounds checking. Change the while condition so that it
is skipped if states count is zero.

Signed-off-by: Gerard Marull-Paretas <[email protected]>
  • Loading branch information
gmarull authored and carlescufi committed Nov 11, 2022
1 parent 96f1ee9 commit 442fae1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/pinctrl/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ int pinctrl_lookup_state(const struct pinctrl_dev_config *config, uint8_t id,
const struct pinctrl_state **state)
{
*state = &config->states[0];
while (*state <= &config->states[config->state_cnt - 1U]) {
while (*state < &config->states[config->state_cnt]) {
if (id == (*state)->id) {
return 0;
}
Expand Down

0 comments on commit 442fae1

Please sign in to comment.