[PATCH v3] arm: mvebu: fix null pointer when access

Li Jun posted 1 patch 2 weeks, 5 days ago
There is a newer version of this series
arch/arm/mach-mvebu/board-v7.c      | 6 ++++++
arch/arm/mach-mvebu/coherency.c     | 6 ++++++
arch/arm/mach-mxs/mach-mxs.c        | 4 ++--
arch/arm/mach-versatile/versatile.c | 6 ++++++
4 files changed, 20 insertions(+), 2 deletions(-)
[PATCH v3] arm: mvebu: fix null pointer when access
Posted by Li Jun 2 weeks, 5 days ago
the kzalloc&kstrdup may return null pointer, will cause kernel panic.

-Fix null pointer.

Signed-off-by: Li Jun <lijun01@kylinos.cn>
---
 arch/arm/mach-mvebu/board-v7.c      | 6 ++++++
 arch/arm/mach-mvebu/coherency.c     | 6 ++++++
 arch/arm/mach-mxs/mach-mxs.c        | 4 ++--
 arch/arm/mach-versatile/versatile.c | 6 ++++++
 4 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-mvebu/board-v7.c b/arch/arm/mach-mvebu/board-v7.c
index 04ad651d13a0..25a9853f925e 100644
--- a/arch/arm/mach-mvebu/board-v7.c
+++ b/arch/arm/mach-mvebu/board-v7.c
@@ -128,8 +128,14 @@ static void __init i2c_quirk(void)
 		struct property *new_compat;
 
 		new_compat = kzalloc(sizeof(*new_compat), GFP_KERNEL);
+		if (!new_compat)
+			return -ENOMEM;
 
 		new_compat->name = kstrdup("compatible", GFP_KERNEL);
+		if (!mew_compat->name) {
+			kfree(new_compat);
+			return -ENOMEM;
+		}
 		new_compat->length = sizeof("marvell,mv78230-a0-i2c");
 		new_compat->value = kstrdup("marvell,mv78230-a0-i2c",
 						GFP_KERNEL);
diff --git a/arch/arm/mach-mvebu/coherency.c b/arch/arm/mach-mvebu/coherency.c
index a6b621ff0b87..2c1668f3174c 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)
+			return -ENOMEM;
 		p->name = kstrdup("arm,io-coherent", GFP_KERNEL);
+		if (!p->name) {
+			kfree(p);
+			return -ENOMEM;
+		}
 		of_add_property(cache_dn, p);
 	}
 }
diff --git a/arch/arm/mach-mxs/mach-mxs.c b/arch/arm/mach-mxs/mach-mxs.c
index 6e017fa306c8..16506d9392b4 100644
--- a/arch/arm/mach-mxs/mach-mxs.c
+++ b/arch/arm/mach-mxs/mach-mxs.c
@@ -178,14 +178,14 @@ static void __init update_fec_mac_prop(enum mac_oui oui)
 
 		newmac = kzalloc(sizeof(*newmac) + 6, GFP_KERNEL);
 		if (!newmac)
-			return;
+			return -ENOMEM;
 		newmac->value = newmac + 1;
 		newmac->length = 6;
 
 		newmac->name = kstrdup("local-mac-address", GFP_KERNEL);
 		if (!newmac->name) {
 			kfree(newmac);
-			return;
+			return -ENOMEM;
 		}
 
 		/*
diff --git a/arch/arm/mach-versatile/versatile.c b/arch/arm/mach-versatile/versatile.c
index f0c80d4663ca..07f2a299c770 100644
--- a/arch/arm/mach-versatile/versatile.c
+++ b/arch/arm/mach-versatile/versatile.c
@@ -147,7 +147,13 @@ static void __init versatile_dt_pci_init(void)
 		goto out_put_node;
 
 	newprop->name = kstrdup("status", GFP_KERNEL);
+	if (!newprop->name)
+		goto out_put_node;
+
 	newprop->value = kstrdup("disabled", GFP_KERNEL);
+	if (!newprop->value)
+		goto out_put_node;
+
 	newprop->length = sizeof("disabled");
 	of_update_property(np, newprop);
 
-- 
2.25.1