public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvmem: core: Fix memory leak in nvmem_cell_write
@ 2015-09-19 12:54 Axel Lin
  0 siblings, 0 replies; only message in thread
From: Axel Lin @ 2015-09-19 12:54 UTC (permalink / raw)
  To: Srinivas Kandagatla, Maxime Ripard; +Cc: linux-kernel

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>
---
 drivers/nvmem/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index c39723a..bde792d 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -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))
-- 
2.1.4




^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-09-19 12:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-19 12:54 [PATCH] nvmem: core: Fix memory leak in nvmem_cell_write Axel Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox