cnxk_gpio_valid(struct cnxk_gpiochip *gpiochip, int gpio)
validates the GPIO number with only an upper bound while gpio
can be wrongly configured as negative value from application.
Added a check to reject negative values.
Fixes: ecc0dd455e9a ("raw/cnxk_gpio: add option to select subset of GPIOs")
Cc: [email protected]
Signed-off-by: Akhil Goyal <[email protected]>
---
drivers/raw/cnxk_gpio/cnxk_gpio.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/raw/cnxk_gpio/cnxk_gpio.c
b/drivers/raw/cnxk_gpio/cnxk_gpio.c
index 0549e326f9..e22fb7cf7b 100644
--- a/drivers/raw/cnxk_gpio/cnxk_gpio.c
+++ b/drivers/raw/cnxk_gpio/cnxk_gpio.c
@@ -795,7 +795,7 @@ cnxk_gpio_process_buf(struct cnxk_gpio *gpio, struct
rte_rawdev_buf *rbuf)
static bool
cnxk_gpio_valid(struct cnxk_gpiochip *gpiochip, int gpio)
{
- return gpio < gpiochip->num_gpios && gpiochip->gpios[gpio];
+ return (gpio >= 0) && (gpio < gpiochip->num_gpios) &&
gpiochip->gpios[gpio];
}
static int
--
2.43.0