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

nvmem: core: Fix memory leak in nvmem_cell_write

A tmp buffer is allocated if cell->bit_offset || cell->nbits.
So the tmp buffer needs to be freed at the same condition to avoid leak.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Axel Lin and committed by
Greg Kroah-Hartman
ace22170 cbf854ab

+1 -1
+1 -1
drivers/nvmem/core.c
··· 938 938 rc = regmap_raw_write(nvmem->regmap, cell->offset, buf, cell->bytes); 939 939 940 940 /* free the tmp buffer */ 941 - if (cell->bit_offset) 941 + if (cell->bit_offset || cell->nbits) 942 942 kfree(buf); 943 943 944 944 if (IS_ERR_VALUE(rc))