nvmem: core: fix error path in nvmem_add_cells()

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 <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
This commit is contained in:
Rasmus Villemoes authored and Greg Kroah-Hartman committed 2016-02-11 19:23:28 -08:00
1 parent 990162f038
commit dfdf141429
1 file changed
+3 -1
+3 -1
View 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;
}