Skip to contentSkip to conversation

irqchip/sifive-plic: Fix error codes

PATCH Applied Charlie Jenkins 5 participants 5 messages Sep 3, 2024 – Nov 12, 2024

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 irqchip/sifive-plic: Fix error codes

Set error to -ENOMEM if kcalloc() fails or if irq_domain_add_linear() fails inside of plic_probe().

---
 drivers/irqchip/irq-sifive-plic.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/irqchip/irq-sifive-plic.c +6 -2
index 2f6ef5c495bd..0b730e305748 100644
@@ -626,8 +626,10 @@ static int plic_probe(struct fwnode_handle *fwnode)
 
 		handler->enable_save = kcalloc(DIV_ROUND_UP(nr_irqs, 32),
 					       sizeof(*handler->enable_save), GFP_KERNEL);
-		if (!handler->enable_save)
+		if (!handler->enable_save) {
+			error = -ENOMEM;
 			goto fail_cleanup_contexts;
+		}
 done:
 		for (hwirq = 1; hwirq <= nr_irqs; hwirq++) {
 			plic_toggle(handler, hwirq, 0);
@@ -639,8 +641,10 @@ static int plic_probe(struct fwnode_handle *fwnode)
 
 	priv->irqdomain = irq_domain_create_linear(fwnode, nr_irqs + 1,
 						   &plic_irqdomain_ops, priv);
-	if (WARN_ON(!priv->irqdomain))
+	if (WARN_ON(!priv->irqdomain)) {
+		error = -ENOMEM;
 		goto fail_cleanup_contexts;
+	}
 
 	/*
 	 * We can have multiple PLIC instances so setup global state

---
base-commit: 6804f0edbe7747774e6ae60f20cec4ee3ad7c187
change-id: 20240903-correct_error_codes_sifive_plic-4611f59291df

Signature · 1 line
- Charlie
reviewer Reviewed-by on v1 1/1
#1 lore raw

Hi Charlie,

Quoted 7 lines · Charlie Jenkins

Set error to -ENOMEM if kcalloc() fails or if irq_domain_add_linear() fails inside of plic_probe().

I found the following Fixes tag:

Fixes 4d936f10ff80 ("irqchip/sifive-plic: Probe plic driver early for Allwinner D1 platform")
Quoted 9 lines
---
  drivers/irqchip/irq-sifive-plic.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
drivers/irqchip/irq-sifive-plic.c +0 -0
index 2f6ef5c495bd..0b730e305748 100644

drivers/irqchip/irq-sifive-plic.c static int plic_probe(struct fwnode_handle *fwnode) · line 630

Quoted 6 lines
drivers/irqchip/irq-sifive-plic.c +2 -1
@@ -626,8 +626,10 @@ static int plic_probe(struct fwnode_handle *fwnode)
 
  		handler->enable_save = kcalloc(DIV_ROUND_UP(nr_irqs, 32),
  					       sizeof(*handler->enable_save), GFP_KERNEL);
-		if (!handler->enable_save)
+		if (!handler->enable_save) {
+			error = -ENOMEM;

This is correct.

drivers/irqchip/irq-sifive-plic.c static int plic_probe(struct fwnode_handle *fwnode) · line 645

Quoted 12 lines
drivers/irqchip/irq-sifive-plic.c +3 -1
  			goto fail_cleanup_contexts;
+		}
  done:
  		for (hwirq = 1; hwirq <= nr_irqs; hwirq++) {
  			plic_toggle(handler, hwirq, 0);
@@ -639,8 +641,10 @@ static int plic_probe(struct fwnode_handle *fwnode)
 
  	priv->irqdomain = irq_domain_create_linear(fwnode, nr_irqs + 1,
  						   &plic_irqdomain_ops, priv);
-	if (WARN_ON(!priv->irqdomain))
+	if (WARN_ON(!priv->irqdomain)) {
+		error = -ENOMEM;

Here though I found drivers that return either ENODEV (https://elixir.bootlin.com/linux/v6.11/source/drivers/irqchip/irq-gic.c#L1210) or ENOMEM (https://elixir.bootlin.com/linux/v6.11/source/drivers/irqchip/irq-imx-mu-msi.c#L229).

Before the commit I mentioned above, we used to return ENOMEM. IMHO it's not a big deal as long as we return something different from 0 in that case, I just mention it if someone thinks differently.

You can add:

And I would also add:

Thanks,

Alex

Quoted 9 lines
drivers/irqchip/irq-sifive-plic.c +1 -1
  		goto fail_cleanup_contexts;
+	}
 
  	/*
  	 * We can have multiple PLIC instances so setup global state
 
---

base-commit: 6804f0edbe7747774e6ae60f20cec4ee3ad7c187
change-id: 20240903-correct_error_codes_sifive_plic-4611f59291df

Reviewed-by on v1 1/1
#2 lore raw
In reply to Charlie Jenkins
Quoted 4 lines · Charlie Jenkins

Set error to -ENOMEM if kcalloc() fails or if irq_domain_add_linear() fails inside of plic_probe().

Like Alex mentioned, please include a Fixes tag.

Quoted 4 lines

LGTM.

Regards,
Anup

Quoted 40 lines
---
 drivers/irqchip/irq-sifive-plic.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/irqchip/irq-sifive-plic.c +6 -3
index 2f6ef5c495bd..0b730e305748 100644
@@ -626,8 +626,10 @@ static int plic_probe(struct fwnode_handle *fwnode)
 
                handler->enable_save = kcalloc(DIV_ROUND_UP(nr_irqs, 32),
                                               sizeof(*handler->enable_save), GFP_KERNEL);
-               if (!handler->enable_save)
+               if (!handler->enable_save) {
+                       error = -ENOMEM;
                        goto fail_cleanup_contexts;
+               }
 done:
                for (hwirq = 1; hwirq <= nr_irqs; hwirq++) {
                        plic_toggle(handler, hwirq, 0);
@@ -639,8 +641,10 @@ static int plic_probe(struct fwnode_handle *fwnode)
 
        priv->irqdomain = irq_domain_create_linear(fwnode, nr_irqs + 1,
                                                   &plic_irqdomain_ops, priv);
-       if (WARN_ON(!priv->irqdomain))
+       if (WARN_ON(!priv->irqdomain)) {
+               error = -ENOMEM;
                goto fail_cleanup_contexts;
+       }
 
        /*
         * We can have multiple PLIC instances so setup global state
 
---

base-commit: 6804f0edbe7747774e6ae60f20cec4ee3ad7c187
change-id: 20240903-correct_error_codes_sifive_plic-4611f59291df --
- Charlie

#3 lore raw

[tip: irq/urgent] irqchip/sifive-plic: Return error code on failure

In reply to Charlie Jenkins
The following commit has been merged into the irq/urgent branch of tip:

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

Commit-ID:     6eabf656048d904d961584de2e1d45bc0854f9fb
Gitweb:        https://git.kernel.org/tip/6eabf656048d904d961584de2e1d45bc0854f9fb
Author:        Charlie Jenkins <[email protected]>
AuthorDate:    Tue, 03 Sep 2024 16:36:19 -07:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Wed, 02 Oct 2024 15:15:33 +02:00

irqchip/sifive-plic: Return error code on failure

Set error to -ENOMEM if kcalloc() fails or if irq_domain_add_linear() fails inside of plic_probe() instead of returning 0.

---
 drivers/irqchip/irq-sifive-plic.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/irqchip/irq-sifive-plic.c +6 -2
index 2f6ef5c..0b730e3 100644
@@ -626,8 +626,10 @@ static int plic_probe(struct fwnode_handle *fwnode)
 
 		handler->enable_save = kcalloc(DIV_ROUND_UP(nr_irqs, 32),
 					       sizeof(*handler->enable_save), GFP_KERNEL);
-		if (!handler->enable_save)
+		if (!handler->enable_save) {
+			error = -ENOMEM;
 			goto fail_cleanup_contexts;
+		}
 done:
 		for (hwirq = 1; hwirq <= nr_irqs; hwirq++) {
 			plic_toggle(handler, hwirq, 0);
@@ -639,8 +641,10 @@ done:
 
 	priv->irqdomain = irq_domain_create_linear(fwnode, nr_irqs + 1,
 						   &plic_irqdomain_ops, priv);
-	if (WARN_ON(!priv->irqdomain))
+	if (WARN_ON(!priv->irqdomain)) {
+		error = -ENOMEM;
 		goto fail_cleanup_contexts;
+	}
 
 	/*
 	 * We can have multiple PLIC instances so setup global state
#4 lore raw
In reply to Charlie Jenkins
This patch was applied to riscv/linux.git (fixes) by Thomas Gleixner <[email protected]>:

Hello:

This patch was applied to riscv/linux.git (fixes)
by Thomas Gleixner <[email protected]>:

Quoted 9 lines · On Tue, 03 Sep 2024 16:36:19 -0700 you wrote:

Set error to -ENOMEM if kcalloc() fails or if irq_domain_add_linear() fails inside of plic_probe().

[...]

Here is the summary with links:
- irqchip/sifive-plic: Fix error codes

    https://git.kernel.org/riscv/c/6eabf656048d

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html