Skip to contentSkip to conversation

ARM: mvebu: potential dereference of null pointer

PATCH In review [email protected] 2 participants 2 messages Jan 17, 2023 – Jan 18, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: mvebu: potential dereference of null pointer

From: Minghao Chi <[email protected]>

The return value of kzalloc() needs to be checked. To avoid use of null pointer in case of the failure of alloc.

---
 arch/arm/mach-mvebu/board-v7.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/mach-mvebu/board-v7.c +2 -1
index fd5d0c8ff695..b93b4a8a8357 100644
@@ -125,7 +125,8 @@ static void __init i2c_quirk(void)
 		struct property *new_compat;
 
 		new_compat = kzalloc(sizeof(*new_compat), GFP_KERNEL);
-
+		if (!new_compat)
+			return;
 		new_compat->name = kstrdup("compatible", GFP_KERNEL);
 		new_compat->length = sizeof("marvell,mv78230-a0-i2c");
 		new_compat->value = kstrdup("marvell,mv78230-a0-i2c",
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 17 lines · On Tue, Jan 17, 2023 at 06:22:04PM +0800, [email protected] wrote:

From: Minghao Chi <[email protected]>

The return value of kzalloc() needs to be checked. To avoid use of null pointer in case of the failure of alloc.

---
 arch/arm/mach-mvebu/board-v7.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/mach-mvebu/board-v7.c +0 -0
index fd5d0c8ff695..b93b4a8a8357 100644

arch/arm/mach-mvebu/board-v7.c static void __init i2c_quirk(void) · line 132

Quoted 9 lines
arch/arm/mach-mvebu/board-v7.c +2 -1
@@ -125,7 +125,8 @@ static void __init i2c_quirk(void)
 		struct property *new_compat;
 
 		new_compat = kzalloc(sizeof(*new_compat), GFP_KERNEL);
-
+		if (!new_compat)
+			return;
 		new_compat->name = kstrdup("compatible", GFP_KERNEL);
 		new_compat->length = sizeof("marvell,mv78230-a0-i2c");
 		new_compat->value = kstrdup("marvell,mv78230-a0-i2c",

Please add a blank line after the return statement.

Also, i find it interested your bot is telling you about kzalloc, but totally ignoring kstrdup().

Andrew

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel