* [PATCH] ARM, sched/topology: Check return value of kcalloc()
@ 2024-06-28 19:43 Thorsten Blum
2024-06-28 21:55 ` Russell King (Oracle)
0 siblings, 1 reply; 3+ messages in thread
From: Thorsten Blum @ 2024-06-28 19:43 UTC (permalink / raw)
To: linux; +Cc: mingo, sshegde, linux-arm-kernel, linux-kernel, Thorsten Blum
Check the return value of kcalloc() and return early if memory
allocation fails.
Compile-tested only.
Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
---
arch/arm/kernel/topology.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/arm/kernel/topology.c b/arch/arm/kernel/topology.c
index 2336ee2aa44a..b77d1838e5a3 100644
--- a/arch/arm/kernel/topology.c
+++ b/arch/arm/kernel/topology.c
@@ -93,6 +93,10 @@ static void __init parse_dt_topology(void)
__cpu_capacity = kcalloc(nr_cpu_ids, sizeof(*__cpu_capacity),
GFP_NOWAIT);
+ if (unlikely(!__cpu_capacity)) {
+ pr_crit("Failed to allocate memory for __cpu_capacity\n");
+ return;
+ }
for_each_possible_cpu(cpu) {
const __be32 *rate;
--
2.45.2
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] ARM, sched/topology: Check return value of kcalloc()
2024-06-28 19:43 [PATCH] ARM, sched/topology: Check return value of kcalloc() Thorsten Blum
@ 2024-06-28 21:55 ` Russell King (Oracle)
2024-06-29 4:09 ` Thorsten Blum
0 siblings, 1 reply; 3+ messages in thread
From: Russell King (Oracle) @ 2024-06-28 21:55 UTC (permalink / raw)
To: Thorsten Blum; +Cc: mingo, sshegde, linux-arm-kernel, linux-kernel
On Fri, Jun 28, 2024 at 09:43:51PM +0200, Thorsten Blum wrote:
> Check the return value of kcalloc() and return early if memory
> allocation fails.
If we fail this allocation even with your fix, how likely is it that the
system will boot and manage to run userspace?
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ARM, sched/topology: Check return value of kcalloc()
2024-06-28 21:55 ` Russell King (Oracle)
@ 2024-06-29 4:09 ` Thorsten Blum
0 siblings, 0 replies; 3+ messages in thread
From: Thorsten Blum @ 2024-06-29 4:09 UTC (permalink / raw)
To: Russell King (Oracle); +Cc: mingo, sshegde, linux-arm-kernel, linux-kernel
On 28. Jun 2024, at 14:55, Russell King (Oracle) <linux@armlinux.org.uk> wrote:
> On Fri, Jun 28, 2024 at 09:43:51PM +0200, Thorsten Blum wrote:
>> Check the return value of kcalloc() and return early if memory
>> allocation fails.
>
> If we fail this allocation even with your fix, how likely is it that the
> system will boot and manage to run userspace?
I thought about panicking, but wasn't sure if it's justified.
But since it would just crash anyway when accessing a NULL pointer
later on, it's probably best to panic() if the memory allocation fails.
I'll submit a v2 shortly.
Thanks,
Thorsten
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-06-29 4:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-28 19:43 [PATCH] ARM, sched/topology: Check return value of kcalloc() Thorsten Blum
2024-06-28 21:55 ` Russell King (Oracle)
2024-06-29 4:09 ` Thorsten Blum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).