All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH next] gpio: aggregator: Fix off by one in gpiochip_fwd_desc_add()
@ 2025-08-13  5:38 Dan Carpenter
  2025-08-13  6:50 ` Geert Uytterhoeven
  2025-08-13  7:23 ` Bartosz Golaszewski
  0 siblings, 2 replies; 5+ messages in thread
From: Dan Carpenter @ 2025-08-13  5:38 UTC (permalink / raw)
  To: Thomas Richard
  Cc: Geert Uytterhoeven, Linus Walleij, Bartosz Golaszewski,
	Andy Shevchenko, linux-gpio, linux-kernel, kernel-janitors

The "> chip->ngpio" comparison here needs to be ">= chip->ngpio",
otherwise it leads to an out of bounds access.  The fwd->valid_mask
bitmap only has chip->ngpio bits and the fwd->descs[] array has that
same number of elements.  These values are set in
devm_gpiochip_fwd_alloc().

Fixes: c44ce91b8ada ("gpio: aggregator: refactor the code to add GPIO desc in the forwarder")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/gpio/gpio-aggregator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c
index 0ef6556f98b1..37600faf4a4b 100644
--- a/drivers/gpio/gpio-aggregator.c
+++ b/drivers/gpio/gpio-aggregator.c
@@ -744,7 +744,7 @@ int gpiochip_fwd_desc_add(struct gpiochip_fwd *fwd, struct gpio_desc *desc,
 {
 	struct gpio_chip *chip = &fwd->chip;
 
-	if (offset > chip->ngpio)
+	if (offset >= chip->ngpio)
 		return -EINVAL;
 
 	if (test_and_set_bit(offset, fwd->valid_mask))
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-08-14  9:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-13  5:38 [PATCH next] gpio: aggregator: Fix off by one in gpiochip_fwd_desc_add() Dan Carpenter
2025-08-13  6:50 ` Geert Uytterhoeven
2025-08-13  7:23 ` Bartosz Golaszewski
2025-08-14  8:42   ` Linus Walleij
2025-08-14  9:32     ` Bartosz Golaszewski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.