Skip to content

Commit

Permalink
nvmem: core: Fix memory leak in nvmem_cell_write
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Axel Lin authored and Greg Kroah-Hartman committed Oct 4, 2015
1 parent cbf854a commit ace2217
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/nvmem/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len)
rc = regmap_raw_write(nvmem->regmap, cell->offset, buf, cell->bytes);

/* free the tmp buffer */
if (cell->bit_offset)
if (cell->bit_offset || cell->nbits)
kfree(buf);

if (IS_ERR_VALUE(rc))
Expand Down

0 comments on commit ace2217

Please sign in to comment.