ARM: 9119/1: amba: Properly handle device probe without IRQ domain
authorWang Kefeng <wangkefeng.wang@huawei.com>
Mon, 23 Aug 2021 09:41:43 +0000 (10:41 +0100)
committerRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Tue, 19 Oct 2021 09:30:53 +0000 (10:30 +0100)
of_amba_device_create() uses irq_of_parse_and_map() to translate
a DT interrupt specification into a Linux virtual interrupt number.

But it doesn't properly handle the case where the interrupt controller
is not yet available, eg, when pl011 interrupt is connected to MBIGEN
interrupt controller, because the mbigen initialization is too late,
which will lead to no IRQ due to no IRQ domain found, log is shown below,
  "irq: no irq domain found for uart0 !"

use of_irq_get() to return -EPROBE_DEFER as above, and in the function
amba_device_try_add()/amba_device_add(), it will properly handle in such
case, also return 0 in other fail cases to be consistent as before.

Cc: Rob Herring <robh+dt@kernel.org>
Cc: Frank Rowand <frowand.list@gmail.com>
Reported-by: Ruizhe Lin <linruizhe@huawei.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
drivers/amba/bus.c
drivers/of/platform.c

index 36f2f42c8014c847890070044d5c70449ac142e7..720aa6cdd40250870df56dd4a1ae004d40c8d3dc 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/clk/clk-conf.h>
 #include <linux/platform_device.h>
 #include <linux/reset.h>
+#include <linux/of_irq.h>
 
 #include <asm/irq.h>
 
@@ -371,12 +372,38 @@ static void amba_device_release(struct device *dev)
        kfree(d);
 }
 
+static int of_amba_device_decode_irq(struct amba_device *dev)
+{
+       struct device_node *node = dev->dev.of_node;
+       int i, irq = 0;
+
+       if (IS_ENABLED(CONFIG_OF_IRQ) && node) {
+               /* Decode the IRQs and address ranges */
+               for (i = 0; i < AMBA_NR_IRQS; i++) {
+                       irq = of_irq_get(node, i);
+                       if (irq < 0) {
+                               if (irq == -EPROBE_DEFER)
+                                       return irq;
+                               irq = 0;
+                       }
+
+                       dev->irq[i] = irq;
+               }
+       }
+
+       return 0;
+}
+
 static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
 {
        u32 size;
        void __iomem *tmp;
        int i, ret;
 
+       ret = of_amba_device_decode_irq(dev);
+       if (ret)
+               goto err_out;
+
        ret = request_resource(parent, &dev->res);
        if (ret)
                goto err_out;
index 74afbb7a4f5ecb5c7ee4424f84e754ad215b49ba..32d5ff8df74719edf56e2ad4b1f732c6ed5267a5 100644 (file)
@@ -222,7 +222,7 @@ static struct amba_device *of_amba_device_create(struct device_node *node,
 {
        struct amba_device *dev;
        const void *prop;
-       int i, ret;
+       int ret;
 
        pr_debug("Creating amba device %pOF\n", node);
 
@@ -253,10 +253,6 @@ static struct amba_device *of_amba_device_create(struct device_node *node,
        if (prop)
                dev->periphid = of_read_ulong(prop, 1);
 
-       /* Decode the IRQs and address ranges */
-       for (i = 0; i < AMBA_NR_IRQS; i++)
-               dev->irq[i] = irq_of_parse_and_map(node, i);
-
        ret = of_address_to_resource(node, 0, &dev->res);
        if (ret) {
                pr_err("amba: of_address_to_resource() failed (%d) for %pOF\n",