Skip to contentSkip to conversation

irqchip/sifive-plic: Fix error handling of of_property_read_u32

PATCH In review Qingfang Deng 2 participants 3 messages Mar 22, 2024 – Mar 25, 2024

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

PATCH 1/1 irqchip/sifive-plic: Fix error handling of of_property_read_u32

From: Qingfang Deng <[email protected]>

nr_irqs will not be initialized if of_property_read_u32 returns an error. Check the error first.

Fixes 8237f8bc4f6e ("irqchip: add a SiFive PLIC driver")
---
 drivers/irqchip/irq-sifive-plic.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/irqchip/irq-sifive-plic.c +4 -1
index 5b7bc4fd9517..f436b61d74b0 100644
@@ -428,8 +428,11 @@ static int __init __plic_init(struct device_node *node,
 		goto out_free_priv;
 	}
 
+	error = of_property_read_u32(node, "riscv,ndev", &nr_irqs);
+	if (error)
+		goto out_iounmap;
+
 	error = -EINVAL;
-	of_property_read_u32(node, "riscv,ndev", &nr_irqs);
 	if (WARN_ON(!nr_irqs))
 		goto out_iounmap;
 
Signature · 1 line
2.34.1
reviewer Reviewed-by on v1 1/1
#1 lore raw

Hi Qingfang,

Quoted 18 lines · Qingfang Deng

From: Qingfang Deng <[email protected]>

nr_irqs will not be initialized if of_property_read_u32 returns an error. Check the error first.

Fixes 8237f8bc4f6e ("irqchip: add a SiFive PLIC driver")
---
  drivers/irqchip/irq-sifive-plic.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/irqchip/irq-sifive-plic.c +0 -0
index 5b7bc4fd9517..f436b61d74b0 100644
@@ -428,8 +428,11 @@ static int __init __plic_init(struct device_node *node,
  		goto out_free_priv;
  	}

drivers/irqchip/irq-sifive-plic.c static int __init __plic_init(struct device_node *node, · line 438

Quoted 10 lines
drivers/irqchip/irq-sifive-plic.c +4 -1
 
+	error = of_property_read_u32(node, "riscv,ndev", &nr_irqs);
+	if (error)
+		goto out_iounmap;
+
  	error = -EINVAL;
-	of_property_read_u32(node, "riscv,ndev", &nr_irqs);
  	if (WARN_ON(!nr_irqs))
  		goto out_iounmap;
 

You can add:

Thanks,

Alex

#2 lore raw

Hi Qingfang,

Quoted 14 lines · Alexandre Ghiti

Hi Qingfang,

Quoted 11 lines · Qingfang Deng

From: Qingfang Deng <[email protected]>

nr_irqs will not be initialized if of_property_read_u32 returns an error. Check the error first.

Fixes 8237f8bc4f6e ("irqchip: add a SiFive PLIC driver")

---
  drivers/irqchip/irq-sifive-plic.c | 5 ++++-

  1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 17 lines
Quoted 6 lines
drivers/irqchip/irq-sifive-plic.c +0 -0
index 5b7bc4fd9517..f436b61d74b0 100644
@@ -428,8 +428,11 @@ static int __init __plic_init(struct device_node 
 *node,

drivers/irqchip/irq-sifive-plic.c static int __init __plic_init(struct device_node · line 437

Quoted 10 lines
drivers/irqchip/irq-sifive-plic.c +3 -1
           goto out_free_priv;
       }
   +    error = of_property_read_u32(node, "riscv,ndev", &nr_irqs);
+    if (error)
+        goto out_iounmap;
+
       error = -EINVAL;
-    of_property_read_u32(node, "riscv,ndev", &nr_irqs);
       if (WARN_ON(!nr_irqs))
           goto out_iounmap;

So this is actually already fixed in 6.9-rc1 by this commit: 956521064780 ("irqchip/sifive-plic: Parse number of interrupts and contexts early in plic_probe()").

Thanks,

Alex

Quoted 14 lines

You can add:

Thanks,

Alex

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv