diff options
author | Markus Schneider-Pargmann <msp@baylibre.com> | 2024-02-24 12:45:16 +0100 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2024-03-07 21:21:53 +0100 |
commit | def3173d4f17b37cecbd74d7c269a080b0b01598 (patch) | |
tree | 6b1a5348f15e617dd6f0e99b536de2fcadb1ca66 /drivers/nvmem | |
parent | nvmem: core: make nvmem_layout_bus_type const (diff) | |
download | linux-def3173d4f17b37cecbd74d7c269a080b0b01598.tar.xz linux-def3173d4f17b37cecbd74d7c269a080b0b01598.zip |
nvmem: core: Print error on wrong bits DT property
The algorithms in nvmem core are built with the constraint that
bit_offset < 8. If bit_offset is greater the results are wrong. Print an
error if the devicetree 'bits' property is outside of the valid range
and abort parsing.
Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20240224114516.86365-12-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/nvmem')
-rw-r--r-- | drivers/nvmem/core.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index eb357ac2e54a..2c6b99402df8 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -807,6 +807,11 @@ static int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_nod if (addr && len == (2 * sizeof(u32))) { info.bit_offset = be32_to_cpup(addr++); info.nbits = be32_to_cpup(addr); + if (info.bit_offset >= BITS_PER_BYTE || info.nbits < 1) { + dev_err(dev, "nvmem: invalid bits on %pOF\n", child); + of_node_put(child); + return -EINVAL; + } } info.np = of_node_get(child); |