Skip to content

Commit

Permalink
gpiolib: Fix incorrect use of find_next_zero_bit()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Janusz Krzysztofik <[email protected]>
Tested-by: Marek Szyprowski <[email protected]>
Signed-off-by: Linus Walleij <[email protected]>
  • Loading branch information
jkrzyszt authored and linusw committed Oct 1, 2018
1 parent be8c8fa commit 799d5eb
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions drivers/gpio/gpiolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2920,12 +2920,11 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep,
int hwgpio = gpio_chip_hwgpio(desc);

__set_bit(hwgpio, mask);
i++;

if (array_info)
i = find_next_zero_bit(array_info->get_mask,
array_size, i);
else
i++;
} while ((i < array_size) &&
(desc_array[i]->gdev->chip == chip));

Expand All @@ -2945,12 +2944,11 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep,
value = !value;
__assign_bit(j, value_bitmap, value);
trace_gpio_value(desc_to_gpio(desc), 1, value);
j++;

if (array_info)
j = find_next_zero_bit(array_info->get_mask, i,
j);
else
j++;
}

if (mask != fastpath)
Expand Down Expand Up @@ -3233,12 +3231,11 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep,
__clear_bit(hwgpio, bits);
count++;
}
i++;

if (array_info)
i = find_next_zero_bit(array_info->set_mask,
array_size, i);
else
i++;
} while ((i < array_size) &&
(desc_array[i]->gdev->chip == chip));
/* push collected bits to outputs */
Expand Down

0 comments on commit 799d5eb

Please sign in to comment.