nvmem: core: fix error path in nvmem_add_cells()
authorRasmus Villemoes <linux@rasmusvillemoes.dk>
Mon, 8 Feb 2016 21:04:29 +0000 (22:04 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 12 Feb 2016 03:23:28 +0000 (19:23 -0800)
The current code fails to nvmem_cell_drop(cells[0]) - even worse, if
the loop above fails already at i==0, we'll enter an essentially
infinite loop doing nvmem_cell_drop on cells[-1], cells[-2], ... which
is unlikely to end well.

Also, we're not freeing the temporary backing array cells on the error
path.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/nvmem/core.c

index 9d11d98..de14fae 100644 (file)
@@ -294,9 +294,11 @@ static int nvmem_add_cells(struct nvmem_device *nvmem,
 
        return 0;
 err:
-       while (--i)
+       while (i--)
                nvmem_cell_drop(cells[i]);
 
+       kfree(cells);
+
        return rval;
 }