diff mbox series

[v5,4/5] nvmem: core: update raw_len if the bit reading is required

Message ID 20250217-sar2130p-nvmem-v5-4-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
If NVMEM cell uses bit offset or specifies bit truncation, update
raw_len manually (following the cell->bytes update), ensuring that the
NVMEM access is still word-aligned.

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

Patch

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index ad9b716e8123537fb5fcef724a684e6db3c1de8e..b6f8544fd9662cff0a04e292bb536418564f0368 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -594,9 +594,11 @@  static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem,
 	cell->nbits = info->nbits;
 	cell->np = info->np;
 
-	if (cell->nbits)
+	if (cell->nbits) {
 		cell->bytes = DIV_ROUND_UP(cell->nbits + cell->bit_offset,
 					   BITS_PER_BYTE);
+		cell->raw_len = ALIGN(cell->bytes, nvmem->word_size);
+	}
 
 	if (!IS_ALIGNED(cell->offset, nvmem->stride)) {
 		dev_err(&nvmem->dev,