[PATCH] nvmem: core: fix read_buffer in place

From: Jorge Ramirez-Ortiz
Date: Thu Feb 28 2019 - 09:22:25 EST


All unused/extra bytes in the cell buffer must be zeroed.

Signed-off-by: Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@xxxxxxxxxx>
---
drivers/nvmem/core.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

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 */
--
2.20.1