Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <linux@rasmusvillemoes.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Rasmus Villemoes and committed by
Greg Kroah-Hartman
dfdf1414 990162f0

+3 -1
+3 -1
drivers/nvmem/core.c
··· 294 294 295 295 return 0; 296 296 err: 297 - while (--i) 297 + while (i--) 298 298 nvmem_cell_drop(cells[i]); 299 + 300 + kfree(cells); 299 301 300 302 return rval; 301 303 }