From: Rasmus Villemoes Date: Mon, 8 Feb 2016 21:04:29 +0000 (+0100) Subject: nvmem: core: fix error path in nvmem_add_cells() X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=dfdf141429f0895b63c882facc42c86f225033cb;p=linux-beck.git 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 Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 9d11d9837312..de14fae6f7f6 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -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; }