Skip to content

Commit 799d5eb

Browse files
jkrzysztLinus Walleij
authored andcommitted
gpiolib: Fix incorrect use of find_next_zero_bit()
Commit b17566a ("gpiolib: Implement fast processing path in get/set array"), already fixed to some extent with commit 5d581d7e8cdc ("gpiolib: Fix missing updates of bitmap index"), introduced a new mode of processing bitmaps where bits applicable for fast bitmap processing path are supposed to be skipped while iterating bits which don't apply. Unfortunately, find_next_zero_bit() function supposed to skip over those fast bits is always called with a 'start' argument equal to an index of last zero bit found and returns that index value again an again, causing an infinite loop. Fix it by incrementing the index uncoditionally before find_next_zero_bit() is optionally called. Reported-by: Marek Szyprowski <m.szyprowski@samsung.com> Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com> Tested-by: Marek Szyprowski <m.szyprowski@samsung.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent be8c8fa commit 799d5eb

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

‎drivers/gpio/gpiolib.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2920,12 +2920,11 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep,
29202920
int hwgpio = gpio_chip_hwgpio(desc);
29212921

29222922
__set_bit(hwgpio, mask);
2923+
i++;
29232924

29242925
if (array_info)
29252926
i = find_next_zero_bit(array_info->get_mask,
29262927
array_size, i);
2927-
else
2928-
i++;
29292928
} while ((i < array_size) &&
29302929
(desc_array[i]->gdev->chip == chip));
29312930

@@ -2945,12 +2944,11 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep,
29452944
value = !value;
29462945
__assign_bit(j, value_bitmap, value);
29472946
trace_gpio_value(desc_to_gpio(desc), 1, value);
2947+
j++;
29482948

29492949
if (array_info)
29502950
j = find_next_zero_bit(array_info->get_mask, i,
29512951
j);
2952-
else
2953-
j++;
29542952
}
29552953

29562954
if (mask != fastpath)
@@ -3233,12 +3231,11 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep,
32333231
__clear_bit(hwgpio, bits);
32343232
count++;
32353233
}
3234+
i++;
32363235

32373236
if (array_info)
32383237
i = find_next_zero_bit(array_info->set_mask,
32393238
array_size, i);
3240-
else
3241-
i++;
32423239
} while ((i < array_size) &&
32433240
(desc_array[i]->gdev->chip == chip));
32443241
/* push collected bits to outputs */

0 commit comments

Comments
 (0)