ARM: mvebu: Prevent null pointer dereference caused by kzalloc failure

Message ID 20240225060401.52768-1-duoming@zju.edu.cn
State New
Headers
Series ARM: mvebu: Prevent null pointer dereference caused by kzalloc failure |

Commit Message

Duoming Zhou Feb. 25, 2024, 6:04 a.m. UTC
  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@zju.edu.cn>
---
 arch/arm/mach-mvebu/board-v7.c | 2 ++
 1 file changed, 2 insertions(+)
  

Patch

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");