From c0fd9b31c55a9b7648ebad21c2584e8201b7057f Mon Sep 17 00:00:00 2001 From: Jett Rink Date: Wed, 11 Nov 2020 11:04:45 -0700 Subject: zephyr: bounds check remaining gpio shim functions I missed a few bound checks in the gpio shim. Add a bound check to all remaining gpio shim functions that need it. BRANCH=none BUG=b:172512307 TEST=volteer, posix-ec, and test/app/ec all build without warnings Signed-off-by: Jett Rink Change-Id: Id915532b83e1621c86253fe86137034751a4da6d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2532683 Commit-Queue: Jack Rosenthal Reviewed-by: Jack Rosenthal --- zephyr/shim/src/gpio.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/zephyr/shim/src/gpio.c b/zephyr/shim/src/gpio.c index 89f9a53451..ab10f08c5e 100644 --- a/zephyr/shim/src/gpio.c +++ b/zephyr/shim/src/gpio.c @@ -106,6 +106,9 @@ struct gpio_signal_callback gpio_interrupts[] = { static struct gpio_signal_callback * get_interrupt_from_signal(enum gpio_signal signal) { + if (signal >= ARRAY_SIZE(configs)) + return NULL; + for (size_t i = 0; i < ARRAY_SIZE(gpio_interrupts); i++) { if (gpio_interrupts[i].signal == signal) return &gpio_interrupts[i]; @@ -172,6 +175,9 @@ static int convert_from_zephyr_flags(const gpio_flags_t zephyr) int gpio_get_default_flags(enum gpio_signal signal) { + if (signal >= ARRAY_SIZE(configs)) + return 0; + return convert_from_zephyr_flags(configs[signal].init_flags); } -- cgit v1.2.1