On 13.01.2021 10:07, Hans Petter Selasky wrote:
The branch main has been updated by hselasky:

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

commit bafb682656724d06045fa494efb83a4312036f1f
Author:     Hans Petter Selasky <hsela...@freebsd.org>
AuthorDate: 2021-01-12 17:46:09 +0000
Commit:     Hans Petter Selasky <hsela...@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.

Why? All supported compilers are familiar with this variable declaration. It is explicitly allowed by style (9) and makes the code much more readable, IMHO.

Michal

     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);
        }

_______________________________________________
dev-commits-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-all
To unsubscribe, send any mail to "dev-commits-src-all-unsubscr...@freebsd.org"

Reply via email to