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

Linus Walleij
2016-06-18T08:54:28Z

On Fri, Jun 17, 2016 at 11:28 AM, walter harms <wharms@bfs.de> wrote:
> Am 17.06.2016 11:15, schrieb Dan Carpenter:

>> 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]);
>
> just my two cents,

The loop looks like that for a reason: i is indexing upwards while
grabbing the descriptors, then it rewinds that way to free them if
something went wrong during init.