[PATCH v2] ARM: mvebu: Add error handling in coherency.c to prevent bugs

Duoming Zhou duoming at zju.edu.cn
Sun Feb 25 06:31:22 PST 2024


The kzalloc() and kstrdup() in armada_375_380_coherency_init()
will return null if the physical memory has run out. As a result,
if we dereference these null pointers, the null pointer dereference
bugs will happen.

This patch adds error handling to avoid null pointer dereference.

Fixes: 497a92308af8 ("ARM: mvebu: implement L2/PCIe deadlock workaround")
Signed-off-by: Duoming Zhou <duoming at zju.edu.cn>
---
Changes in v2:
  - Adds checks to judge whether kstrdup() fails.

 arch/arm/mach-mvebu/coherency.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm/mach-mvebu/coherency.c b/arch/arm/mach-mvebu/coherency.c
index a6b621ff0b8..be50c83bfef 100644
--- a/arch/arm/mach-mvebu/coherency.c
+++ b/arch/arm/mach-mvebu/coherency.c
@@ -191,7 +191,13 @@ static void __init armada_375_380_coherency_init(struct device_node *np)
 		struct property *p;
 
 		p = kzalloc(sizeof(*p), GFP_KERNEL);
+		if (!p)
+			continue;
 		p->name = kstrdup("arm,io-coherent", GFP_KERNEL);
+		if (!p->name) {
+			kfree(p);
+			continue;
+		}
 		of_add_property(cache_dn, p);
 	}
 }
-- 
2.17.1




More information about the linux-arm-kernel mailing list