17bab2480261e492e35e90aad897812518d7548c
[openwrt/staging/blocktrron.git] /
1 From def3173d4f17b37cecbd74d7c269a080b0b01598 Mon Sep 17 00:00:00 2001
2 From: Markus Schneider-Pargmann <msp@baylibre.com>
3 Date: Sat, 24 Feb 2024 11:45:16 +0000
4 Subject: [PATCH] nvmem: core: Print error on wrong bits DT property
5
6 The algorithms in nvmem core are built with the constraint that
7 bit_offset < 8. If bit_offset is greater the results are wrong. Print an
8 error if the devicetree 'bits' property is outside of the valid range
9 and abort parsing.
10
11 Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com>
12 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
13 Link: https://lore.kernel.org/r/20240224114516.86365-12-srinivas.kandagatla@linaro.org
14 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
15 ---
16 drivers/nvmem/core.c | 5 +++++
17 1 file changed, 5 insertions(+)
18
19 --- a/drivers/nvmem/core.c
20 +++ b/drivers/nvmem/core.c
21 @@ -806,6 +806,11 @@ static int nvmem_add_cells_from_dt(struc
22 if (addr && len == (2 * sizeof(u32))) {
23 info.bit_offset = be32_to_cpup(addr++);
24 info.nbits = be32_to_cpup(addr);
25 + if (info.bit_offset >= BITS_PER_BYTE || info.nbits < 1) {
26 + dev_err(dev, "nvmem: invalid bits on %pOF\n", child);
27 + of_node_put(child);
28 + return -EINVAL;
29 + }
30 }
31
32 info.np = of_node_get(child);