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

From: Duoming Zhou
Date: Sun Feb 25 2024 - 01:04:52 EST


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@xxxxxxxxxx>
---
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