Skip to contentSkip to conversation

nvmem: core: Fix memory leak in nvmem_cell_write

PATCH New Axel Lin 1 participant 1 message Sep 19, 2015 NVMEM framework

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 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.

---
 drivers/nvmem/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvmem/core.c +1 -1
index c39723a..bde792d 100644
@@ -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))
Signature · 1 line
2.1.4