git: bafb68265672 - main - Fix for off-by-one in GPIO driver after r368585. While at it declare the iteration variable outside the for-loop to appease older compilers.

Hans Petter Selasky hselasky at FreeBSD.org
Wed Jan 13 09:07:20 UTC 2021


The branch main has been updated by hselasky:

URL: https://cgit.FreeBSD.org/src/commit/?id=bafb682656724d06045fa494efb83a4312036f1f

commit bafb682656724d06045fa494efb83a4312036f1f
Author:     Hans Petter Selasky <hselasky at FreeBSD.org>
AuthorDate: 2021-01-12 17:46:09 +0000
Commit:     Hans Petter Selasky <hselasky at FreeBSD.org>
CommitDate: 2021-01-13 09:06:30 +0000

    Fix for off-by-one in GPIO driver after r368585.
    While at it declare the iteration variable outside the for-loop
    to appease older compilers.
    
    Sponsored by:   Mellanox Technologies // NVIDIA Networking
---
 sys/dev/gpio/gpioc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/sys/dev/gpio/gpioc.c b/sys/dev/gpio/gpioc.c
index 727b07a70589..83d55742a3a2 100644
--- a/sys/dev/gpio/gpioc.c
+++ b/sys/dev/gpio/gpioc.c
@@ -567,6 +567,7 @@ gpioc_probe(device_t dev)
 static int
 gpioc_attach(device_t dev)
 {
+	int i;
 	int err;
 	struct gpioc_softc *sc;
 	struct make_dev_args devargs;
@@ -582,7 +583,7 @@ gpioc_attach(device_t dev)
 		return (err);
 	sc->sc_pin_intr = malloc(sizeof(struct gpioc_pin_intr) * sc->sc_npins,
 	    M_GPIOC, M_WAITOK | M_ZERO);
-	for (int i = 0; i <= sc->sc_npins; i++) {
+	for (i = 0; i < sc->sc_npins; i++) {
 		sc->sc_pin_intr[i].pin = malloc(sizeof(struct gpiobus_pin),
 		    M_GPIOC, M_WAITOK | M_ZERO);
 		sc->sc_pin_intr[i].sc = sc;
@@ -612,11 +613,12 @@ gpioc_detach(device_t dev)
 {
 	struct gpioc_softc *sc = device_get_softc(dev);
 	int err;
+	int i;
 
 	if (sc->sc_ctl_dev)
 		destroy_dev(sc->sc_ctl_dev);
 
-	for (int i = 0; i <= sc->sc_npins; i++) {
+	for (i = 0; i < sc->sc_npins; i++) {
 		mtx_destroy(&sc->sc_pin_intr[i].mtx);
 		free(&sc->sc_pin_intr[i].pin, M_GPIOC);
 	}


More information about the dev-commits-src-all mailing list