public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] irqdesc: Fail check on early_irq_init allocation.
@ 2023-11-11 17:00 Paran Lee
  2023-11-12 14:00 ` Marc Zyngier
  0 siblings, 1 reply; 5+ messages in thread
From: Paran Lee @ 2023-11-11 17:00 UTC (permalink / raw)
  To: Thomas Gleixner, Marc Zyngier
  Cc: linux-kernel, shjy180909, austindh.kim, Paran Lee

When doing start_kernel(),
On early_irq_init(), alloc_desc() or alloc_percpu()
may be fails. So, Explicit fail check needed on dynamic allocation.

Signed-off-by: Paran Lee <p4ranlee@gmail.com>
---
 kernel/irq/irqdesc.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c
index 27ca1c866f29..bdc35823e4c4 100644
--- a/kernel/irq/irqdesc.c
+++ b/kernel/irq/irqdesc.c
@@ -565,6 +565,7 @@ int __init early_irq_init(void)
 
 	for (i = 0; i < initcnt; i++) {
 		desc = alloc_desc(i, node, 0, NULL, NULL);
+		BUG_ON(!desc);
 		irq_insert_desc(i, desc);
 	}
 	return arch_early_irq_init();
@@ -582,18 +583,16 @@ struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = {
 
 int __init early_irq_init(void)
 {
-	int count, i, node = first_online_node;
-	struct irq_desc *desc;
+	int count = ARRAY_SIZE(irq_desc), i, node = first_online_node;
+	struct irq_desc *desc = irq_desc;
 
 	init_irq_default_affinity();
 
 	printk(KERN_INFO "NR_IRQS: %d\n", NR_IRQS);
 
-	desc = irq_desc;
-	count = ARRAY_SIZE(irq_desc);
-
 	for (i = 0; i < count; i++) {
 		desc[i].kstat_irqs = alloc_percpu(unsigned int);
+		BUG_ON(!desc[i].kstat_irqs);
 		alloc_masks(&desc[i], node);
 		raw_spin_lock_init(&desc[i].lock);
 		lockdep_set_class(&desc[i].lock, &irq_desc_lock_class);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-11-12 15:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-11 17:00 [PATCH] irqdesc: Fail check on early_irq_init allocation Paran Lee
2023-11-12 14:00 ` Marc Zyngier
2023-11-12 14:19   ` Paran Lee
2023-11-12 15:08     ` Marc Zyngier
2023-11-12 15:21       ` Paran Lee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox