diff mbox series

nvmem: core: fix read_buffer in place

Message ID 20190228142204.9873-1-jorge.ramirez-ortiz@linaro.org
State New
Headers show
Series nvmem: core: fix read_buffer in place | expand

Commit Message

Jorge Ramirez-Ortiz Feb. 28, 2019, 2:22 p.m. UTC
All unused/extra bytes in the cell buffer must be zeroed.

Signed-off-by: Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>

---
 drivers/nvmem/core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

-- 
2.20.1
diff mbox series

Patch

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index f7301bb4ef3b..65e198adebac 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -1162,7 +1162,7 @@  EXPORT_SYMBOL_GPL(nvmem_cell_put);
 static void nvmem_shift_read_buffer_in_place(struct nvmem_cell *cell, void *buf)
 {
 	u8 *p, *b;
-	int i, bit_offset = cell->bit_offset;
+	int i, extra, bit_offset = cell->bit_offset;
 
 	p = b = buf;
 	if (bit_offset) {
@@ -1179,7 +1179,8 @@  static void nvmem_shift_read_buffer_in_place(struct nvmem_cell *cell, void *buf)
 		}
 
 		/* result fits in less bytes */
-		if (cell->bytes != DIV_ROUND_UP(cell->nbits, BITS_PER_BYTE))
+		extra = cell->bytes - DIV_ROUND_UP(cell->nbits, BITS_PER_BYTE);
+		while (--extra >= 0)
 			*p-- = 0;
 	}
 	/* clear msb bits if any leftover in the last byte */