Skip to contentSkip to conversation

usb: dwc2: Register interrupt handler only once gadget is correctly initialized

PATCH In review Romain Perier 2 participants 5 messages Feb 6, 2015 – Feb 21, 2015

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

PATCH v2 1/1 usb: dwc2: Register interrupt handler only once gadget is correctly initialized

Don't register interrupt handler before usb gadget is correctly initialized. For some embedded platforms which don't have a usb-phy, it crashes the driver because an interrupt is emitted with non-initialized hardware. According to devm_request_irq documentation, an interrupt can be emitted at any time once the interrupt is registered, so we have to care about driver and hardware initialization.

---

Changes for v2: fix typos in commit log

 drivers/usb/dwc2/platform.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/usb/dwc2/platform.c +9 -8
index ae095f0..b26cf8c 100644
@@ -196,14 +196,6 @@ static int dwc2_driver_probe(struct platform_device *dev)
 		return irq;
 	}
 
-	dev_dbg(hsotg->dev, "registering common handler for irq%d\n",
-		irq);
-	retval = devm_request_irq(hsotg->dev, irq,
-				  dwc2_handle_common_intr, IRQF_SHARED,
-				  dev_name(hsotg->dev), hsotg);
-	if (retval)
-		return retval;
-
 	res = platform_get_resource(dev, IORESOURCE_MEM, 0);
 	hsotg->regs = devm_ioremap_resource(&dev->dev, res);
 	if (IS_ERR(hsotg->regs))
@@ -237,6 +229,15 @@ static int dwc2_driver_probe(struct platform_device *dev)
 	retval = dwc2_gadget_init(hsotg, irq);
 	if (retval)
 		return retval;
+
+        dev_dbg(hsotg->dev, "registering common handler for irq%d\n",
+                irq);
+        retval = devm_request_irq(hsotg->dev, irq,
+                                dwc2_handle_common_intr, IRQF_SHARED,
+                                dev_name(hsotg->dev), hsotg);
+        if (retval)
+                return retval;
+
 	retval = dwc2_hcd_init(hsotg, irq, params);
 	if (retval)
 		return retval;
Signature · 1 line
1.9.1
#1 lore raw

ping

2015-02-06 17:50 GMT+01:00 Romain Perier <[email protected]>:

Quoted 53 lines

Don't register interrupt handler before usb gadget is correctly initialized. For some embedded platforms which don't have a usb-phy, it crashes the driver because an interrupt is emitted with non-initialized hardware. According to devm_request_irq documentation, an interrupt can be emitted at any time once the interrupt is registered, so we have to care about driver and hardware initialization.

---

Changes for v2: fix typos in commit log

 drivers/usb/dwc2/platform.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/usb/dwc2/platform.c +9 -9
index ae095f0..b26cf8c 100644
@@ -196,14 +196,6 @@ static int dwc2_driver_probe(struct platform_device *dev)
                return irq;
        }
 
-       dev_dbg(hsotg->dev, "registering common handler for irq%d\n",
-               irq);
-       retval = devm_request_irq(hsotg->dev, irq,
-                                 dwc2_handle_common_intr, IRQF_SHARED,
-                                 dev_name(hsotg->dev), hsotg);
-       if (retval)
-               return retval;
-
        res = platform_get_resource(dev, IORESOURCE_MEM, 0);
        hsotg->regs = devm_ioremap_resource(&dev->dev, res);
        if (IS_ERR(hsotg->regs))
@@ -237,6 +229,15 @@ static int dwc2_driver_probe(struct platform_device *dev)
        retval = dwc2_gadget_init(hsotg, irq);
        if (retval)
                return retval;
+
+        dev_dbg(hsotg->dev, "registering common handler for irq%d\n",
+                irq);
+        retval = devm_request_irq(hsotg->dev, irq,
+                                dwc2_handle_common_intr, IRQF_SHARED,
+                                dev_name(hsotg->dev), hsotg);
+        if (retval)
+                return retval;
+
        retval = dwc2_hcd_init(hsotg, irq, params);
        if (retval)
                return retval;
--

1.9.1

#2 lore raw
Quoted 45 lines · Romain Perier

ping

2015-02-06 17:50 GMT+01:00 Romain Perier <[email protected]>:

Quoted 42 lines

Don't register interrupt handler before usb gadget is correctly initialized. For some embedded platforms which don't have a usb-phy, it crashes the driver because an interrupt is emitted with non-initialized hardware. According to devm_request_irq documentation, an interrupt can be emitted at any time once the interrupt is registered, so we have to care about driver and hardware initialization.

---

Changes for v2: fix typos in commit log

 drivers/usb/dwc2/platform.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/usb/dwc2/platform.c +4 -8
index ae095f0..b26cf8c 100644
@@ -196,14 +196,6 @@ static int dwc2_driver_probe(struct platform_device *dev)
                return irq;
        }
 
-       dev_dbg(hsotg->dev, "registering common handler for irq%d\n",
-               irq);
-       retval = devm_request_irq(hsotg->dev, irq,
-                                 dwc2_handle_common_intr, IRQF_SHARED,
-                                 dev_name(hsotg->dev), hsotg);
-       if (retval)
-               return retval;
-
        res = platform_get_resource(dev, IORESOURCE_MEM, 0);
        hsotg->regs = devm_ioremap_resource(&dev->dev, res);
        if (IS_ERR(hsotg->regs))
@@ -237,6 +229,15 @@ static int dwc2_driver_probe(struct platform_device *dev)
        retval = dwc2_gadget_init(hsotg, irq);
        if (retval)
                return retval;
+
+        dev_dbg(hsotg->dev, "registering common handler for irq%d\n",
+                irq);
+        retval = devm_request_irq(hsotg->dev, irq,
Quoted 8 lines

drivers/usb/dwc2/platform.c static int dwc2_driver_probe(struct platform_device *dev) · line 243

Quoted 8 lines
drivers/usb/dwc2/platform.c +5 -0
+                                dwc2_handle_common_intr, IRQF_SHARED,
+                                dev_name(hsotg->dev), hsotg);
+        if (retval)
+                return retval;
+
        retval = dwc2_hcd_init(hsotg, irq, params);
        if (retval)
                return retval;

Hi,

I'm going to be away until Wednesday, Feb 18. I'll take a look at this and other pending dwc2 patches at that time.

Regards,
John

#3 lore raw

No problem

Regards,
Romain

2015-02-13 3:47 GMT+01:00 John Youn <[email protected]>:

Quoted 64 lines · Romain Perier
Quoted 45 lines

ping

2015-02-06 17:50 GMT+01:00 Romain Perier <[email protected]>:

Quoted 42 lines

Don't register interrupt handler before usb gadget is correctly initialized. For some embedded platforms which don't have a usb-phy, it crashes the driver because an interrupt is emitted with non-initialized hardware. According to devm_request_irq documentation, an interrupt can be emitted at any time once the interrupt is registered, so we have to care about driver and hardware initialization.

---

Changes for v2: fix typos in commit log

 drivers/usb/dwc2/platform.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/usb/dwc2/platform.c +4 -8
index ae095f0..b26cf8c 100644
@@ -196,14 +196,6 @@ static int dwc2_driver_probe(struct platform_device *dev)
                return irq;
        }
 
-       dev_dbg(hsotg->dev, "registering common handler for irq%d\n",
-               irq);
-       retval = devm_request_irq(hsotg->dev, irq,
-                                 dwc2_handle_common_intr, IRQF_SHARED,
-                                 dev_name(hsotg->dev), hsotg);
-       if (retval)
-               return retval;
-
        res = platform_get_resource(dev, IORESOURCE_MEM, 0);
        hsotg->regs = devm_ioremap_resource(&dev->dev, res);
        if (IS_ERR(hsotg->regs))
@@ -237,6 +229,15 @@ static int dwc2_driver_probe(struct platform_device *dev)
        retval = dwc2_gadget_init(hsotg, irq);
        if (retval)
                return retval;
+
+        dev_dbg(hsotg->dev, "registering common handler for irq%d\n",
+                irq);
+        retval = devm_request_irq(hsotg->dev, irq,
Quoted 8 lines

drivers/usb/dwc2/platform.c static int dwc2_driver_probe(struct platform_device *dev) · line 243

Quoted 8 lines
drivers/usb/dwc2/platform.c +5 -0
+                                dwc2_handle_common_intr, IRQF_SHARED,
+                                dev_name(hsotg->dev), hsotg);
+        if (retval)
+                return retval;
+
        retval = dwc2_hcd_init(hsotg, irq, params);
        if (retval)
                return retval;

Hi,

I'm going to be away until Wednesday, Feb 18. I'll take a look at this and other pending dwc2 patches at that time.

Regards,
John

#4 lore raw
In reply to Romain Perier
Quoted 41 lines · Romain Perier

Don't register interrupt handler before usb gadget is correctly initialized. For some embedded platforms which don't have a usb-phy, it crashes the driver because an interrupt is emitted with non-initialized hardware. According to devm_request_irq documentation, an interrupt can be emitted at any time once the interrupt is registered, so we have to care about driver and hardware initialization.

---

Changes for v2: fix typos in commit log

 drivers/usb/dwc2/platform.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/usb/dwc2/platform.c +2 -8
index ae095f0..b26cf8c 100644
@@ -196,14 +196,6 @@ static int dwc2_driver_probe(struct platform_device *dev)
 		return irq;
 	}
 
-	dev_dbg(hsotg->dev, "registering common handler for irq%d\n",
-		irq);
-	retval = devm_request_irq(hsotg->dev, irq,
-				  dwc2_handle_common_intr, IRQF_SHARED,
-				  dev_name(hsotg->dev), hsotg);
-	if (retval)
-		return retval;
-
 	res = platform_get_resource(dev, IORESOURCE_MEM, 0);
 	hsotg->regs = devm_ioremap_resource(&dev->dev, res);
 	if (IS_ERR(hsotg->regs))
@@ -237,6 +229,15 @@ static int dwc2_driver_probe(struct platform_device *dev)
 	retval = dwc2_gadget_init(hsotg, irq);
 	if (retval)
 		return retval;
+
+        dev_dbg(hsotg->dev, "registering common handler for irq%d\n",

drivers/usb/dwc2/platform.c static int dwc2_driver_probe(struct platform_device *dev) · line 243

Quoted 10 lines
drivers/usb/dwc2/platform.c +7 -0
+                irq);
+        retval = devm_request_irq(hsotg->dev, irq,
+                                dwc2_handle_common_intr, IRQF_SHARED,
+                                dev_name(hsotg->dev), hsotg);
+        if (retval)
+                return retval;
+
 	retval = dwc2_hcd_init(hsotg, irq, params);
 	if (retval)
 		return retval;

This patch fails checkpatch.pl.

Which interrupt is being emitted?

You are only initializing the gadget side before registering the handler. Could it affect the host side as well, say if you config for HOST only? In that case none of the dwc2_gadget_init() will be done (as it is a no-op).

Thanks,
John