From e4859d2e9a9de74734519d0c1e01c7e0d18e7bc9 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 11 Jun 2016 21:30:19 -0400 Subject: [PATCH] gpio: Fix off-by-one bug in check for the maximum gpio port Signed-off-by: Kevin O'Connor --- src/avr/gpio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/avr/gpio.c b/src/avr/gpio.c index 4ec1e316..9f947e7a 100644 --- a/src/avr/gpio.c +++ b/src/avr/gpio.c @@ -137,7 +137,7 @@ static const uint8_t ADMUX_DEFAULT = 0x40; struct gpio_out gpio_out_setup(uint8_t pin, uint8_t val) { - if (GPIO2PORT(pin) > ARRAY_SIZE(digital_regs)) + if (GPIO2PORT(pin) >= ARRAY_SIZE(digital_regs)) goto fail; struct gpio_digital_regs *regs = GPIO2REGS(pin); if (! regs) @@ -168,7 +168,7 @@ gpio_out_write(struct gpio_out g, uint8_t val) struct gpio_in gpio_in_setup(uint8_t pin, int8_t pull_up) { - if (GPIO2PORT(pin) > ARRAY_SIZE(digital_regs)) + if (GPIO2PORT(pin) >= ARRAY_SIZE(digital_regs)) goto fail; struct gpio_digital_regs *regs = GPIO2REGS(pin); if (! regs)