From 333559f2f175aea22abeb030978bdf4dd5e76d69 Mon Sep 17 00:00:00 2001 From: Ian Lepore Date: Thu, 5 Jul 2018 14:09:48 +0000 Subject: [PATCH] Fix an out-of-bounds array access... the irq data for teardown is in two arrays, as elements 0 and 1 of one array and elements 1 and 2 of the other. Run the loop 0..1 instead of 1..2 and use named constants to offset into one of the arrays. PR: 229508 --- sys/arm/freescale/imx/imx_gpio.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sys/arm/freescale/imx/imx_gpio.c b/sys/arm/freescale/imx/imx_gpio.c index 5e0ad3430ce..d7d38fcbb6c 100644 --- a/sys/arm/freescale/imx/imx_gpio.c +++ b/sys/arm/freescale/imx/imx_gpio.c @@ -134,6 +134,8 @@ static struct resource_spec imx_gpio_spec[] = { { SYS_RES_IRQ, 1, RF_ACTIVE }, { -1, 0 } }; +#define FIRST_IRQRES 1 +#define NUM_IRQRES 2 /* * Helpers @@ -852,9 +854,10 @@ imx51_gpio_detach(device_t dev) sc = device_get_softc(dev); gpiobus_detach_bus(dev); - for (irq = 1; irq <= 2; irq++) { + for (irq = 0; irq < NUM_IRQRES; irq++) { if (sc->gpio_ih[irq]) - bus_teardown_intr(dev, sc->sc_res[irq], sc->gpio_ih[irq]); + bus_teardown_intr(dev, sc->sc_res[irq + FIRST_IRQRES], + sc->gpio_ih[irq]); } bus_release_resources(dev, imx_gpio_spec, sc->sc_res); mtx_destroy(&sc->sc_mtx);