gpio: Fix off-by-one bug in check for the maximum gpio port

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2016-06-11 21:30:19 -04:00
parent 91e7807af6
commit e4859d2e9a
1 changed files with 2 additions and 2 deletions

View File

@ -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)