mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] irqchip/sifive-plic: Panic if initialization fails
@ 2026-09-11 14:50 Nam Cao
  2026-09-13 21:46 ` Radu Rendec
  2026-10-15  9:54 ` [tip: irq/drivers] " tip-bot2 for Nam Cao
  0 siblings, 2 replies; 3+ messages in thread
From: Nam Cao @ 2026-09-11 14:50 UTC (permalink / raw)
  To: Thomas Gleixner, Radu Rendec, Paul Walmsley, Samuel Holland,
	Anup Patel, linux-kernel, linux-riscv
  Cc: Nam Cao

If PLIC initialization fails, the driver unwinds and returns an error.
However, that is futile because the system cannot function without the
PLIC: all device interrupts are routed through it.

Instead of the unnecessary cleanups, panic when PLIC initialization fails.

Signed-off-by: Nam Cao <namcao@linutronix.de>
---
 drivers/irqchip/irq-sifive-plic.c | 56 +++++++++----------------------
 1 file changed, 15 insertions(+), 41 deletions(-)

diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c
index a7cddadddf40..70a7478373e4 100644
--- a/drivers/irqchip/irq-sifive-plic.c
+++ b/drivers/irqchip/irq-sifive-plic.c
@@ -643,13 +643,11 @@ static int plic_probe(struct fwnode_handle *fwnode)
 
 	error = plic_parse_nr_irqs_and_contexts(fwnode, &nr_irqs, &nr_contexts, &gsi_base, &id);
 	if (error)
-		goto fail_free_regs;
+		return error;
 
 	priv = kzalloc_obj(*priv);
-	if (!priv) {
-		error = -ENOMEM;
-		goto fail_free_regs;
-	}
+	if (!priv)
+		return -ENOMEM;
 
 	priv->fwnode = fwnode;
 	priv->plic_quirks = plic_quirks;
@@ -668,10 +666,8 @@ static int plic_probe(struct fwnode_handle *fwnode)
 	priv->acpi_plic_id = id;
 
 	priv->prio_save = bitmap_zalloc(nr_irqs, GFP_KERNEL);
-	if (!priv->prio_save) {
-		error = -ENOMEM;
-		goto fail_free_priv;
-	}
+	if (!priv->prio_save)
+		return -ENOMEM;
 
 	for (i = 0; i < nr_contexts; i++) {
 		error = plic_parse_context_parent(fwnode, i, &parent_hwirq, &cpu,
@@ -735,10 +731,8 @@ static int plic_probe(struct fwnode_handle *fwnode)
 
 		handler->enable_save = kcalloc(priv->irq_groups, sizeof(*handler->enable_save),
 					       GFP_KERNEL);
-		if (!handler->enable_save) {
-			error = -ENOMEM;
-			goto fail_cleanup_contexts;
-		}
+		if (!handler->enable_save)
+			return -ENOMEM;
 done:
 		for_each_device_irq(hwirq, priv) {
 			plic_toggle(handler, hwirq, 0);
@@ -748,10 +742,8 @@ static int plic_probe(struct fwnode_handle *fwnode)
 	}
 
 	priv->irqdomain = irq_domain_create_linear(fwnode, nr_irqs, &plic_irqdomain_ops, priv);
-	if (WARN_ON(!priv->irqdomain)) {
-		error = -ENOMEM;
-		goto fail_cleanup_contexts;
-	}
+	if (!priv->irqdomain)
+		return -ENOMEM;
 
 	/*
 	 * We can have multiple PLIC instances so setup global state
@@ -799,33 +791,13 @@ static int plic_probe(struct fwnode_handle *fwnode)
 	pr_info("%pfwP: mapped %d interrupts with %d handlers for %d contexts.\n",
 		fwnode, nr_irqs, nr_handlers, nr_contexts);
 	return 0;
-
-fail_cleanup_contexts:
-	for (i = 0; i < nr_contexts; i++) {
-		if (plic_parse_context_parent(fwnode, i, &parent_hwirq, &cpu, priv->acpi_plic_id))
-			continue;
-		if (parent_hwirq != RV_IRQ_EXT || cpu < 0)
-			continue;
-
-		handler = per_cpu_ptr(&plic_handlers, cpu);
-		handler->present = false;
-		handler->hart_base = NULL;
-		handler->enable_base = NULL;
-		kfree(handler->enable_save);
-		handler->enable_save = NULL;
-		handler->priv = NULL;
-	}
-	bitmap_free(priv->prio_save);
-fail_free_priv:
-	kfree(priv);
-fail_free_regs:
-	iounmap(regs);
-	return error;
 }
 
 static int plic_platform_probe(struct platform_device *pdev)
 {
-	return plic_probe(pdev->dev.fwnode);
+	if (plic_probe(pdev->dev.fwnode))
+		panic("%pfwP: Failed to initialize\n", pdev->dev.fwnode);
+	return 0;
 }
 
 static struct platform_driver plic_driver = {
@@ -842,7 +814,9 @@ builtin_platform_driver(plic_driver);
 static int __init plic_early_probe(struct device_node *node,
 				   struct device_node *parent)
 {
-	return plic_probe(&node->fwnode);
+	if (plic_probe(&node->fwnode))
+		panic("%pfwP: Failed to initialize\n", &node->fwnode);
+	return 0;
 }
 
 IRQCHIP_DECLARE(riscv, "allwinner,sun20i-d1-plic", plic_early_probe);
-- 
2.47.3


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

* Re: [PATCH] irqchip/sifive-plic: Panic if initialization fails
  2026-09-11 14:50 [PATCH] irqchip/sifive-plic: Panic if initialization fails Nam Cao
@ 2026-09-13 21:46 ` Radu Rendec
  2026-10-15  9:54 ` [tip: irq/drivers] " tip-bot2 for Nam Cao
  1 sibling, 0 replies; 3+ messages in thread
From: Radu Rendec @ 2026-09-13 21:46 UTC (permalink / raw)
  To: Nam Cao, Thomas Gleixner, Paul Walmsley, Samuel Holland,
	Anup Patel, linux-kernel, linux-riscv

On Fri, 2026-09-11 at 16:50 +0200, Nam Cao wrote:
> If PLIC initialization fails, the driver unwinds and returns an error.
> However, that is futile because the system cannot function without the
> PLIC: all device interrupts are routed through it.
> 
> Instead of the unnecessary cleanups, panic when PLIC initialization fails.
> 
> Signed-off-by: Nam Cao <namcao@linutronix.de>
> ---
>  drivers/irqchip/irq-sifive-plic.c | 56 +++++++++----------------------
>  1 file changed, 15 insertions(+), 41 deletions(-)
> 
> diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c
> index a7cddadddf40..70a7478373e4 100644
> --- a/drivers/irqchip/irq-sifive-plic.c
> +++ b/drivers/irqchip/irq-sifive-plic.c
> @@ -643,13 +643,11 @@ static int plic_probe(struct fwnode_handle *fwnode)
>  
>  	error = plic_parse_nr_irqs_and_contexts(fwnode, &nr_irqs, &nr_contexts, &gsi_base, &id);
>  	if (error)
> -		goto fail_free_regs;
> +		return error;
>  
>  	priv = kzalloc_obj(*priv);
> -	if (!priv) {
> -		error = -ENOMEM;
> -		goto fail_free_regs;
> -	}
> +	if (!priv)
> +		return -ENOMEM;
>  
>  	priv->fwnode = fwnode;
>  	priv->plic_quirks = plic_quirks;
> @@ -668,10 +666,8 @@ static int plic_probe(struct fwnode_handle *fwnode)
>  	priv->acpi_plic_id = id;
>  
>  	priv->prio_save = bitmap_zalloc(nr_irqs, GFP_KERNEL);
> -	if (!priv->prio_save) {
> -		error = -ENOMEM;
> -		goto fail_free_priv;
> -	}
> +	if (!priv->prio_save)
> +		return -ENOMEM;
>  
>  	for (i = 0; i < nr_contexts; i++) {
>  		error = plic_parse_context_parent(fwnode, i, &parent_hwirq, &cpu,
> @@ -735,10 +731,8 @@ static int plic_probe(struct fwnode_handle *fwnode)
>  
>  		handler->enable_save = kcalloc(priv->irq_groups, sizeof(*handler->enable_save),
>  					       GFP_KERNEL);
> -		if (!handler->enable_save) {
> -			error = -ENOMEM;
> -			goto fail_cleanup_contexts;
> -		}
> +		if (!handler->enable_save)
> +			return -ENOMEM;
>  done:
>  		for_each_device_irq(hwirq, priv) {
>  			plic_toggle(handler, hwirq, 0);
> @@ -748,10 +742,8 @@ static int plic_probe(struct fwnode_handle *fwnode)
>  	}
>  
>  	priv->irqdomain = irq_domain_create_linear(fwnode, nr_irqs, &plic_irqdomain_ops, priv);
> -	if (WARN_ON(!priv->irqdomain)) {
> -		error = -ENOMEM;
> -		goto fail_cleanup_contexts;
> -	}
> +	if (!priv->irqdomain)
> +		return -ENOMEM;
>  
>  	/*
>  	 * We can have multiple PLIC instances so setup global state
> @@ -799,33 +791,13 @@ static int plic_probe(struct fwnode_handle *fwnode)
>  	pr_info("%pfwP: mapped %d interrupts with %d handlers for %d contexts.\n",
>  		fwnode, nr_irqs, nr_handlers, nr_contexts);
>  	return 0;
> -
> -fail_cleanup_contexts:
> -	for (i = 0; i < nr_contexts; i++) {
> -		if (plic_parse_context_parent(fwnode, i, &parent_hwirq, &cpu, priv->acpi_plic_id))
> -			continue;
> -		if (parent_hwirq != RV_IRQ_EXT || cpu < 0)
> -			continue;
> -
> -		handler = per_cpu_ptr(&plic_handlers, cpu);
> -		handler->present = false;
> -		handler->hart_base = NULL;
> -		handler->enable_base = NULL;
> -		kfree(handler->enable_save);
> -		handler->enable_save = NULL;
> -		handler->priv = NULL;
> -	}
> -	bitmap_free(priv->prio_save);
> -fail_free_priv:
> -	kfree(priv);
> -fail_free_regs:
> -	iounmap(regs);
> -	return error;
>  }
>  
>  static int plic_platform_probe(struct platform_device *pdev)
>  {
> -	return plic_probe(pdev->dev.fwnode);
> +	if (plic_probe(pdev->dev.fwnode))
> +		panic("%pfwP: Failed to initialize\n", pdev->dev.fwnode);
> +	return 0;
>  }
>  
>  static struct platform_driver plic_driver = {
> @@ -842,7 +814,9 @@ builtin_platform_driver(plic_driver);
>  static int __init plic_early_probe(struct device_node *node,
>  				   struct device_node *parent)
>  {
> -	return plic_probe(&node->fwnode);
> +	if (plic_probe(&node->fwnode))
> +		panic("%pfwP: Failed to initialize\n", &node->fwnode);
> +	return 0;
>  }
>  
>  IRQCHIP_DECLARE(riscv, "allwinner,sun20i-d1-plic", plic_early_probe);

Reviewed-by: Radu Rendec <radu@rendec.net>

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

* [tip: irq/drivers] irqchip/sifive-plic: Panic if initialization fails
  2026-09-11 14:50 [PATCH] irqchip/sifive-plic: Panic if initialization fails Nam Cao
  2026-09-13 21:46 ` Radu Rendec
@ 2026-10-15  9:54 ` tip-bot2 for Nam Cao
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Nam Cao @ 2026-10-15  9:54 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Nam Cao, Thomas Gleixner, Radu Rendec, x86, linux-kernel

The following commit has been merged into the irq/drivers branch of tip:

Commit-ID:     dd6abfd40c6d8788efe81a7023886a8e0b595e29
Gitweb:        https://git.kernel.org/tip/dd6abfd40c6d8788efe81a7023886a8e0b595e29
Author:        Nam Cao <namcao@linutronix.de>
AuthorDate:    Fri, 11 Sep 2026 16:50:37 +02:00
Committer:     Thomas Gleixner <tglx@kernel.org>
CommitterDate: Thu, 15 Oct 2026 11:50:47 +02:00

irqchip/sifive-plic: Panic if initialization fails

If PLIC initialization fails, the driver unwinds and returns an error.
However, that is futile because the system cannot function without the
PLIC: all device interrupts are routed through it.

Instead of the unnecessary cleanups, panic when PLIC initialization fails.

Signed-off-by: Nam Cao <namcao@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Reviewed-by: Radu Rendec <radu@rendec.net>
Link: https://patch.msgid.link/20260911145037.427896-1-namcao@linutronix.de
---
 drivers/irqchip/irq-sifive-plic.c | 56 ++++++++----------------------
 1 file changed, 15 insertions(+), 41 deletions(-)

diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c
index a7cddad..70a7478 100644
--- a/drivers/irqchip/irq-sifive-plic.c
+++ b/drivers/irqchip/irq-sifive-plic.c
@@ -643,13 +643,11 @@ static int plic_probe(struct fwnode_handle *fwnode)
 
 	error = plic_parse_nr_irqs_and_contexts(fwnode, &nr_irqs, &nr_contexts, &gsi_base, &id);
 	if (error)
-		goto fail_free_regs;
+		return error;
 
 	priv = kzalloc_obj(*priv);
-	if (!priv) {
-		error = -ENOMEM;
-		goto fail_free_regs;
-	}
+	if (!priv)
+		return -ENOMEM;
 
 	priv->fwnode = fwnode;
 	priv->plic_quirks = plic_quirks;
@@ -668,10 +666,8 @@ static int plic_probe(struct fwnode_handle *fwnode)
 	priv->acpi_plic_id = id;
 
 	priv->prio_save = bitmap_zalloc(nr_irqs, GFP_KERNEL);
-	if (!priv->prio_save) {
-		error = -ENOMEM;
-		goto fail_free_priv;
-	}
+	if (!priv->prio_save)
+		return -ENOMEM;
 
 	for (i = 0; i < nr_contexts; i++) {
 		error = plic_parse_context_parent(fwnode, i, &parent_hwirq, &cpu,
@@ -735,10 +731,8 @@ static int plic_probe(struct fwnode_handle *fwnode)
 
 		handler->enable_save = kcalloc(priv->irq_groups, sizeof(*handler->enable_save),
 					       GFP_KERNEL);
-		if (!handler->enable_save) {
-			error = -ENOMEM;
-			goto fail_cleanup_contexts;
-		}
+		if (!handler->enable_save)
+			return -ENOMEM;
 done:
 		for_each_device_irq(hwirq, priv) {
 			plic_toggle(handler, hwirq, 0);
@@ -748,10 +742,8 @@ done:
 	}
 
 	priv->irqdomain = irq_domain_create_linear(fwnode, nr_irqs, &plic_irqdomain_ops, priv);
-	if (WARN_ON(!priv->irqdomain)) {
-		error = -ENOMEM;
-		goto fail_cleanup_contexts;
-	}
+	if (!priv->irqdomain)
+		return -ENOMEM;
 
 	/*
 	 * We can have multiple PLIC instances so setup global state
@@ -799,33 +791,13 @@ done:
 	pr_info("%pfwP: mapped %d interrupts with %d handlers for %d contexts.\n",
 		fwnode, nr_irqs, nr_handlers, nr_contexts);
 	return 0;
-
-fail_cleanup_contexts:
-	for (i = 0; i < nr_contexts; i++) {
-		if (plic_parse_context_parent(fwnode, i, &parent_hwirq, &cpu, priv->acpi_plic_id))
-			continue;
-		if (parent_hwirq != RV_IRQ_EXT || cpu < 0)
-			continue;
-
-		handler = per_cpu_ptr(&plic_handlers, cpu);
-		handler->present = false;
-		handler->hart_base = NULL;
-		handler->enable_base = NULL;
-		kfree(handler->enable_save);
-		handler->enable_save = NULL;
-		handler->priv = NULL;
-	}
-	bitmap_free(priv->prio_save);
-fail_free_priv:
-	kfree(priv);
-fail_free_regs:
-	iounmap(regs);
-	return error;
 }
 
 static int plic_platform_probe(struct platform_device *pdev)
 {
-	return plic_probe(pdev->dev.fwnode);
+	if (plic_probe(pdev->dev.fwnode))
+		panic("%pfwP: Failed to initialize\n", pdev->dev.fwnode);
+	return 0;
 }
 
 static struct platform_driver plic_driver = {
@@ -842,7 +814,9 @@ builtin_platform_driver(plic_driver);
 static int __init plic_early_probe(struct device_node *node,
 				   struct device_node *parent)
 {
-	return plic_probe(&node->fwnode);
+	if (plic_probe(&node->fwnode))
+		panic("%pfwP: Failed to initialize\n", &node->fwnode);
+	return 0;
 }
 
 IRQCHIP_DECLARE(riscv, "allwinner,sun20i-d1-plic", plic_early_probe);

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

end of thread, other threads:[~2026-10-15  9:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-11 14:50 [PATCH] irqchip/sifive-plic: Panic if initialization fails Nam Cao
2026-09-13 21:46 ` Radu Rendec
2026-10-15  9:54 ` [tip: irq/drivers] " tip-bot2 for Nam Cao

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

all inboxes | Powered by JetHome®