[Letux-kernel] [PATCH] phy-twl4030-usb: better handle musb_mailbox() failure

Andreas Kemnade andreas at kemnade.info
Sun Aug 21 10:03:27 CEST 2016


setting twl->linkstat = MUSB_UNKNOWN upon error in musb_mailbox as
introduced in
commit 12b7db2bf8b8 ("usb: musb: Return error value from musb_mailbox")
causes twl4030_usb_irq() to not detect a state change form cable connected
to cable disconnected after such an error so that
pm_runtime_put_autosuspend() will not be called and the usage counter
gets unbalanced. Such errors happen e.g. if the omap2430 module is not
(yet) loaded during plug/unplug events.

This patch introduces a flag instead that indicates whether musb
knows about the status and calls musb_mailbox() when it does not
know yet about the status.

Signed-off-by: Andreas Kemnade <andreas at kemnade.info>
---
 drivers/phy/phy-twl4030-usb.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/phy/phy-twl4030-usb.c b/drivers/phy/phy-twl4030-usb.c
index ed98cb6..49737fb 100644
--- a/drivers/phy/phy-twl4030-usb.c
+++ b/drivers/phy/phy-twl4030-usb.c
@@ -173,6 +173,7 @@ struct twl4030_usb {
 	int			irq;
 	enum musb_vbus_id_status linkstat;
 	bool			vbus_supplied;
+	bool			musb_has_seen_linkstat;
 
 	struct delayed_work	id_workaround_work;
 };
@@ -711,9 +712,13 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
 			pm_runtime_mark_last_busy(twl->dev);
 			pm_runtime_put_autosuspend(twl->dev);
 		}
+		twl->musb_has_seen_linkstat = false;
+	}
+
+	if (!twl->musb_has_seen_linkstat) {
 		err = musb_mailbox(status);
-		if (err)
-			twl->linkstat = MUSB_UNKNOWN;
+		if (!err)
+			twl->musb_has_seen_linkstat = true;
 	}
 
 	/* don't schedule during sleep - irq works right then */
@@ -818,6 +823,7 @@ static int twl4030_usb_probe(struct platform_device *pdev)
 	twl->irq		= platform_get_irq(pdev, 0);
 	twl->vbus_supplied	= false;
 	twl->linkstat		= MUSB_UNKNOWN;
+	twl->musb_has_seen_linkstat = false;
 
 	twl->phy.dev		= twl->dev;
 	twl->phy.label		= "twl4030";
-- 
2.1.4



More information about the Letux-kernel mailing list