Re: [patch] gpiolib: potential oops on failure path

Dan Carpenter
2016-06-17T09:59:05Z

On Fri, Jun 17, 2016 at 11:28:33AM +0200, walter harms wrote:
> > out_free_descs:
> > + if (i = GPIOHANDLES_MAX)
> > + i--;
> > for (; i >= 0; i--)
> > gpiod_free(lh->descs[i]);
> > kfree(lh->label);
>
>
> Since we have already noticed that programmes are bad at counting backwards
> is it possible to change the loop into counting up ?
>
> btw: if lh->descs[i] is initialized to NULL it would be more robust just to free everything like:
>
> for(i=0;i< GPIOHANDLES_MAX; i++)
> gpiod_free(lh->descs[i]);
>

Depending on the config gpiod_free(NULL) generates a warning. It's
possible that it will be generated once with the current code actually
but I didn't feel it was worth worrying about that.

Still I wouldn't want to generate 64 warnings.

regards,
dan carpenter