Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Jan 2021 12:13:43 +0100
From:      Michal Meloun <meloun.michal@gmail.com>
To:        Hans Petter Selasky <hselasky@FreeBSD.org>, src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   Re: 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.
Message-ID:  <1bbcc331-9a7a-f2d5-a71b-28e55ef32d40@freebsd.org>
In-Reply-To: <202101130907.10D97J6M058131@gitrepo.freebsd.org>
References:  <202101130907.10D97J6M058131@gitrepo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help


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 <hselasky@FreeBSD.org>
> AuthorDate: 2021-01-12 17:46:09 +0000
> Commit:     Hans Petter Selasky <hselasky@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);
>   	}
> 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1bbcc331-9a7a-f2d5-a71b-28e55ef32d40>