Commit e75f88ef authored by Andrei Lalaev's avatar Andrei Lalaev Committed by Bartosz Golaszewski

gpiolib: of: fix bounds check for 'gpio-reserved-ranges'

Gpiolib interprets the elements of "gpio-reserved-ranges" as "start,size"
because it clears "size" bits starting from the "start" bit in the according
bitmap. So it has to use "greater" instead of "greater or equal" when performs
bounds check to make sure that GPIOs are in the available range.
Previous implementation skipped ranges that include the last GPIO in
the range.

I wrote the mail to the maintainers
(https://lore.kernel.org/linux-gpio/20220412115554.159435-1-andrei.lalaev@emlid.com/T/#u)
of the questioned DTSes (because I couldn't understand how the maintainers
interpreted this property), but I haven't received a response.
Since the questioned DTSes use "gpio-reserved-ranges = <0 4>"
(i.e., the beginning of the range), this patch doesn't affect these DTSes at all.
TBH this patch doesn't break any existing DTSes because none of them
reserve gpios at the end of range.

Fixes: 726cb3ba ("gpiolib: Support 'gpio-reserved-ranges' property")
Signed-off-by: default avatarAndrei Lalaev <andrei.lalaev@emlid.com>
Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Cc: stable@vger.kernel.org
Signed-off-by: default avatarBartosz Golaszewski <brgl@bgdev.pl>
parent 672c0c51
...@@ -910,7 +910,7 @@ static void of_gpiochip_init_valid_mask(struct gpio_chip *chip) ...@@ -910,7 +910,7 @@ static void of_gpiochip_init_valid_mask(struct gpio_chip *chip)
i, &start); i, &start);
of_property_read_u32_index(np, "gpio-reserved-ranges", of_property_read_u32_index(np, "gpio-reserved-ranges",
i + 1, &count); i + 1, &count);
if (start >= chip->ngpio || start + count >= chip->ngpio) if (start >= chip->ngpio || start + count > chip->ngpio)
continue; continue;
bitmap_clear(chip->valid_mask, start, count); bitmap_clear(chip->valid_mask, start, count);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment