[PATCH] ARM: mvebu: Prevent null pointer dereference caused by kzalloc failure

Duoming Zhou duoming at zju.edu.cn
Sat Feb 24 22:04:01 PST 2024


The kzalloc() in i2c_quirk() will return null if the physical
memory has run out. As a result, if we dereference the new_compat
pointer, the null pointer dereference bug will happen.

This patch adds a check to avoid null pointer dereference.

Fixes: 5fd62066d290 ("ARM: mvebu: Add thermal quirk for the Armada 375 DB board")
Signed-off-by: Duoming Zhou <duoming at zju.edu.cn>
---
 arch/arm/mach-mvebu/board-v7.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/mach-mvebu/board-v7.c b/arch/arm/mach-mvebu/board-v7.c
index fd5d0c8ff69..7d2cb12e349 100644
--- a/arch/arm/mach-mvebu/board-v7.c
+++ b/arch/arm/mach-mvebu/board-v7.c
@@ -125,6 +125,8 @@ static void __init i2c_quirk(void)
 		struct property *new_compat;
 
 		new_compat = kzalloc(sizeof(*new_compat), GFP_KERNEL);
+		if (!new_compat)
+			continue;
 
 		new_compat->name = kstrdup("compatible", GFP_KERNEL);
 		new_compat->length = sizeof("marvell,mv78230-a0-i2c");
-- 
2.17.1




More information about the linux-arm-kernel mailing list