diff mbox series

[v5,3/5] nvmem: core: verify cell's raw_len

Message ID 20250217-sar2130p-nvmem-v5-3-2f01049d1eea@linaro.org (mailing list archive)
State Not Applicable
Headers show
Series nvmem: qfprom: add Qualcomm SAR2130P support | expand

Commit Message

Dmitry Baryshkov Feb. 17, 2025, 4:33 p.m. UTC
Check that the NVMEM cell's raw_len is a aligned to word_size. Otherwise
Otherwise drivers might face incomplete read while accessing the last
part of the NVMEM cell.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
 drivers/nvmem/core.c | 8 ++++++++
 1 file changed, 8 insertions(+)
diff mbox series

Patch

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 7872903c08a112f11618a5aa6a42ba505106ef6d..ad9b716e8123537fb5fcef724a684e6db3c1de8e 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -605,6 +605,14 @@  static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem,
 		return -EINVAL;
 	}
 
+	if (!IS_ALIGNED(cell->raw_len, nvmem->word_size)) {
+		dev_err(&nvmem->dev,
+			"cell %s raw len %zd unaligned to nvmem word size %d\n",
+			cell->name ?: "<unknown>", cell->raw_len,
+			nvmem->word_size);
+		return -EINVAL;
+	}
+
 	return 0;
 }