diff mbox series

[v2] ARM, sched/topology: Check return value of kcalloc()

Message ID 20240629233028.275424-2-thorsten.blum@toblux.com (mailing list archive)
State New, archived
Headers show
Series [v2] ARM, sched/topology: Check return value of kcalloc() | expand

Commit Message

Thorsten Blum June 29, 2024, 11:30 p.m. UTC
Check the return value of kcalloc() and panic() if memory allocation
fails.

Compile-tested only.

Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
---
Changes in v2:
- Panic instead of failing gracefully by returning early after feedback
  from Russell King
- Link to v1: https://lore.kernel.org/linux-kernel/20240628194350.542376-2-thorsten.blum@toblux.com/
---
 arch/arm/kernel/topology.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/arch/arm/kernel/topology.c b/arch/arm/kernel/topology.c
index 2336ee2aa44a..27d6527f5fb6 100644
--- a/arch/arm/kernel/topology.c
+++ b/arch/arm/kernel/topology.c
@@ -93,6 +93,8 @@  static void __init parse_dt_topology(void)
 
 	__cpu_capacity = kcalloc(nr_cpu_ids, sizeof(*__cpu_capacity),
 				 GFP_NOWAIT);
+	if (unlikely(!__cpu_capacity))
+		panic("Failed to allocate memory for __cpu_capacity\n");
 
 	for_each_possible_cpu(cpu) {
 		const __be32 *rate;