lkml.org 
[lkml]   [2024]   [Feb]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 1/4] nvmem: core: Read into buffers larger than data
Date
The actual size that nvmem is using internally on a specific platform
with a specific devicetree may not be known in the consumer code. The
maximum size may be available at the same time.

Allow the use of larger buffers in nvmem_cell_read_common() by setting
buffers that are too large to zero before copying into them.

Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com>
---
drivers/nvmem/core.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 980123fb4dde..6fa061ede605 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -1806,12 +1806,14 @@ static int nvmem_cell_read_common(struct device *dev, const char *cell_id,
nvmem_cell_put(cell);
return PTR_ERR(buf);
}
- if (len != count) {
+ if (len > count) {
kfree(buf);
nvmem_cell_put(cell);
return -EINVAL;
+ } else if (len < count) {
+ memset(val + len, 0, count - len);
}
- memcpy(val, buf, count);
+ memcpy(val, buf, len);
kfree(buf);
nvmem_cell_put(cell);

--
2.43.0

\
 
 \ /
  Last update: 2024-05-27 14:50    [W:0.236 / U:0.292 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site