From: jsg Date: Fri, 7 May 2021 01:54:17 +0000 (+0000) Subject: fix bounds tests gpio pin numbering starts at 0 X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=67a9c8684e250bf849fc3d5b01e6e923fd0935f3;p=openbsd fix bounds tests gpio pin numbering starts at 0 ok kettenis@ --- diff --git a/sys/dev/fdt/mvgpio.c b/sys/dev/fdt/mvgpio.c index edac3d78269..aae70e55597 100644 --- a/sys/dev/fdt/mvgpio.c +++ b/sys/dev/fdt/mvgpio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mvgpio.c,v 1.1 2018/03/20 21:23:38 kettenis Exp $ */ +/* $OpenBSD: mvgpio.c,v 1.2 2021/05/07 01:54:17 jsg Exp $ */ /* * Copyright (c) 2018 Mark Kettenis * @@ -103,7 +103,7 @@ mvgpio_config_pin(void *cookie, uint32_t *cells, int config) struct mvgpio_softc *sc = cookie; uint32_t pin = cells[0]; - if (pin > 32) + if (pin >= 32) return; if (config & GPIO_CONFIG_OUTPUT) @@ -121,7 +121,7 @@ mvgpio_get_pin(void *cookie, uint32_t *cells) uint32_t reg; int val; - if (pin > 32) + if (pin >= 32) return 0; reg = HREAD4(sc, GPIO_DIN); @@ -140,7 +140,7 @@ mvgpio_set_pin(void *cookie, uint32_t *cells, int val) uint32_t pin = cells[0]; uint32_t flags = cells[1]; - if (pin > 32) + if (pin >= 32) return; if (flags & GPIO_ACTIVE_LOW) diff --git a/sys/dev/fdt/mvpinctrl.c b/sys/dev/fdt/mvpinctrl.c index 8b07c3dac0e..fe4b722a818 100644 --- a/sys/dev/fdt/mvpinctrl.c +++ b/sys/dev/fdt/mvpinctrl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mvpinctrl.c,v 1.7 2020/05/22 10:06:59 patrick Exp $ */ +/* $OpenBSD: mvpinctrl.c,v 1.8 2021/05/07 01:54:17 jsg Exp $ */ /* * Copyright (c) 2013,2016 Patrick Wildt * Copyright (c) 2016 Mark Kettenis @@ -278,7 +278,7 @@ mvpinctrl_config_pin(void *cookie, uint32_t *cells, int config) struct mvpinctrl_softc *sc = cookie; uint32_t pin = cells[0]; - if (pin > 32) + if (pin >= 32) return; if (config & GPIO_CONFIG_OUTPUT) @@ -296,7 +296,7 @@ mvpinctrl_get_pin(void *cookie, uint32_t *cells) uint32_t reg; int val; - if (pin > 32) + if (pin >= 32) return 0; reg = HREAD4(sc, GPIO_INPUT); @@ -314,7 +314,7 @@ mvpinctrl_set_pin(void *cookie, uint32_t *cells, int val) uint32_t pin = cells[0]; uint32_t flags = cells[1]; - if (pin > 32) + if (pin >= 32) return; if (flags & GPIO_ACTIVE_LOW) diff --git a/sys/dev/fdt/plgpio.c b/sys/dev/fdt/plgpio.c index c1ad923ec89..b72198cd58e 100644 --- a/sys/dev/fdt/plgpio.c +++ b/sys/dev/fdt/plgpio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: plgpio.c,v 1.1 2018/08/26 16:52:16 kettenis Exp $ */ +/* $OpenBSD: plgpio.c,v 1.2 2021/05/07 01:54:17 jsg Exp $ */ /* * Copyright (c) 2018 Mark Kettenis * @@ -106,7 +106,7 @@ plgpio_config_pin(void *cookie, uint32_t *cells, int config) struct plgpio_softc *sc = cookie; uint32_t pin = cells[0]; - if (pin > 8) + if (pin >= 8) return; if (config & GPIO_CONFIG_OUTPUT) @@ -124,7 +124,7 @@ plgpio_get_pin(void *cookie, uint32_t *cells) uint32_t reg; int val; - if (pin > 8) + if (pin >= 8) return 0; reg = HREAD1(sc, GPIODATA(pin)); @@ -141,7 +141,7 @@ plgpio_set_pin(void *cookie, uint32_t *cells, int val) uint32_t pin = cells[0]; uint32_t flags = cells[1]; - if (pin > 8) + if (pin >= 8) return; if (flags & GPIO_ACTIVE_LOW) diff --git a/sys/dev/fdt/sxipio.c b/sys/dev/fdt/sxipio.c index b10839f5369..71a06222770 100644 --- a/sys/dev/fdt/sxipio.c +++ b/sys/dev/fdt/sxipio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sxipio.c,v 1.12 2020/03/29 09:35:10 kettenis Exp $ */ +/* $OpenBSD: sxipio.c,v 1.13 2021/05/07 01:54:17 jsg Exp $ */ /* * Copyright (c) 2010 Miodrag Vallat. * Copyright (c) 2013 Artturi Alm @@ -392,7 +392,7 @@ sxipio_config_pin(void *cookie, uint32_t *cells, int config) uint32_t pin = cells[1]; int mux, off; - if (port > SXIPIO_NPORT || pin > 32) + if (port > SXIPIO_NPORT || pin >= 32) return; mux = (config & GPIO_CONFIG_OUTPUT) ? 1 : 0; @@ -410,7 +410,7 @@ sxipio_get_pin(void *cookie, uint32_t *cells) uint32_t reg; int val; - if (port > SXIPIO_NPORT || pin > 32) + if (port > SXIPIO_NPORT || pin >= 32) return 0; reg = SXIREAD4(sc, SXIPIO_DAT(port)); @@ -430,7 +430,7 @@ sxipio_set_pin(void *cookie, uint32_t *cells, int val) uint32_t flags = cells[2]; uint32_t reg; - if (port > SXIPIO_NPORT || pin > 32) + if (port > SXIPIO_NPORT || pin >= 32) return; reg = SXIREAD4(sc, SXIPIO_DAT(port));