diff options
| author | Dmitry Baryshkov <dmitry.baryshkov@linaro.org> | 2025-04-11 12:22:47 +0100 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2025-06-04 14:41:52 +0200 |
| commit | 497f19cacb3f8387a64ec4302111ed02da23da77 (patch) | |
| tree | 9a3ea3d843a1820e97cbd016de5990a874db05d8 /drivers/nvmem | |
| parent | 04c81ac33a60742ae15b599704148e1a343d3f67 (diff) | |
| download | linux-497f19cacb3f8387a64ec4302111ed02da23da77.tar.gz linux-497f19cacb3f8387a64ec4302111ed02da23da77.tar.bz2 linux-497f19cacb3f8387a64ec4302111ed02da23da77.zip | |
nvmem: core: verify cell's raw_len
[ Upstream commit 13bcd440f2ff38cd7e42a179c223d4b833158b33 ]
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>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20250411112251.68002-10-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'drivers/nvmem')
| -rw-r--r-- | drivers/nvmem/core.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 3ea94bc26e80..3d69c76f1923 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -467,6 +467,18 @@ 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); + + if (info->raw_len) + return -EINVAL; + + cell->raw_len = ALIGN(cell->raw_len, nvmem->word_size); + } + return 0; } |
