Skip to contentSkip to conversation

nvmem: core: Print error on wrong bits DT property

PATCH Applied Markus Schneider-Pargmann 2 participants 2 messages Jan 30, 2024 – Feb 21, 2024 NVMEM framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 drivers/nvmem/core.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/nvmem/core.c +5 -0
index 980123fb4dde..a9832b5a608e 100644
@@ -806,6 +806,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);
Signature · 1 line
2.43.0
#1 lore raw
Quoted 6 lines · Markus Schneider-Pargmann

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.

Applied, thanks!

[1/1] nvmem: core: Print error on wrong bits DT property

      commit: 8bb130f38373b5e405b7d81c6ebc36107e518a99

Best regards,

Signature · 1 line
Srinivas Kandagatla <[email protected]>