From: peter.chen@freescale.com (Peter Chen)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v8 8/8] usb: chipidea: udc: fix the oops when plugs in usb cable after rmmod gadget
Date: Sun, 17 Feb 2013 11:09:53 +0800 [thread overview]
Message-ID: <20130217030951.GA1588@nchen-desktop> (raw)
In-Reply-To: <20130213084128.GB2426@arwen.pp.htv.fi>
On Wed, Feb 13, 2013 at 10:41:28AM +0200, Felipe Balbi wrote:
> Hi,
>
> >
> > Signed-off-by: Peter Chen <peter.chen@freescale.com>
> >
> > diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
> > index b57b735..8319d7e 100644
> > --- a/drivers/usb/chipidea/udc.c
> > +++ b/drivers/usb/chipidea/udc.c
> > @@ -1575,12 +1575,17 @@ static int ci13xxx_stop(struct usb_gadget *gadget,
> >
> > spin_lock_irqsave(&ci->lock, flags);
> >
> > + /*
> > + * Put it at the beginning due to avoid calling gadget
> > + * disconnect at _gadget_stop_activity
> > + */
> > + ci->driver = NULL;
> > +
> > if (ci->vbus_active) {
> > hw_device_state(ci, 0);
> > if (ci->platdata->notify_event)
> > ci->platdata->notify_event(ci,
> > CI13XXX_CONTROLLER_STOPPED_EVENT);
> > - ci->driver = NULL;
> > spin_unlock_irqrestore(&ci->lock, flags);
> > _gadget_stop_activity(&ci->gadget);
> > spin_lock_irqsave(&ci->lock, flags);
>
> NACK, this isn't the real problem. The real problem is that chipidea
> shouldn't be calling ->disconnect() by itself when we unload a gadget
> driver.
Yes, you point the root cause, besides, we also need to notify gadget
when the disconnect occurs even the gadget is still there. Below patch
is tested:
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index b57b735..e355914 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -579,9 +579,6 @@ static int _gadget_stop_activity(struct usb_gadget *gadget)
usb_ep_fifo_flush(&ci->ep0out->ep);
usb_ep_fifo_flush(&ci->ep0in->ep);
- if (ci->driver)
- ci->driver->disconnect(gadget);
-
/* make sure to disable all endpoints */
gadget_for_each_ep(ep, gadget) {
usb_ep_disable(ep);
@@ -612,6 +609,11 @@ __acquires(ci->lock)
dbg_event(0xFF, "BUS RST", 0);
+ if (ci->gadget.speed != USB_SPEED_UNKNOWN) {
+ if (ci->driver)
+ ci->driver->disconnect(&ci->gadget);
+ }
+
spin_unlock(&ci->lock);
retval = _gadget_stop_activity(&ci->gadget);
if (retval)
@@ -1373,6 +1375,8 @@ static int ci13xxx_vbus_session(struct usb_gadget *_gadget, int is_active)
hw_device_state(ci, ci->ep0out->qh.dma);
dev_dbg(ci->dev, "Connected to host\n");
} else {
+ if (ci->driver)
+ ci->driver->disconnect(&ci->gadget);
hw_device_state(ci, 0);
if (ci->platdata->notify_event)
ci->platdata->notify_event(ci,
@@ -1580,13 +1584,14 @@ static int ci13xxx_stop(struct usb_gadget *gadget,
if (ci->platdata->notify_event)
ci->platdata->notify_event(ci,
CI13XXX_CONTROLLER_STOPPED_EVENT);
- ci->driver = NULL;
spin_unlock_irqrestore(&ci->lock, flags);
_gadget_stop_activity(&ci->gadget);
spin_lock_irqsave(&ci->lock, flags);
pm_runtime_put(&ci->gadget.dev);
}
+ ci->driver = NULL;
+
spin_unlock_irqrestore(&ci->lock, flags);
return 0;
--
Best Regards,
Peter Chen
next prev parent reply other threads:[~2013-02-17 3:09 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-05 8:00 [PATCH v8 0/8] Add tested id switch and vbus connect detect support for Chipidea Peter Chen
2013-02-05 8:00 ` [PATCH v8 1/8] Revert "USB: chipidea: add vbus detect for udc" Peter Chen
2013-02-05 8:00 ` [PATCH v8 2/8] usb: chipidea: add otg file Peter Chen
2013-02-05 8:00 ` [PATCH v8 3/8] usb: chipidea: add otg id switch and vbus connect/disconnect detect Peter Chen
2013-02-14 12:37 ` Alexander Shishkin
2013-02-17 3:27 ` Peter Chen
2013-02-05 8:00 ` [PATCH v8 4/8] usb: chipidea: consolidate kinds of APIs for both roles Peter Chen
2013-02-05 8:00 ` [PATCH v8 5/8] usb: chipidea: udc: add pullup/pulldown dp at hw_device_state Peter Chen
2013-02-05 8:00 ` [PATCH v8 6/8] usb: chipidea: udc: retire the flag CI13_PULLUP_ON_VBUS Peter Chen
2013-02-05 8:00 ` [PATCH v8 7/8] usb: chipidea: imx: add internal vbus regulator control Peter Chen
2013-02-05 8:00 ` [PATCH v8 8/8] usb: chipidea: udc: fix the oops when plugs in usb cable after rmmod gadget Peter Chen
2013-02-13 8:41 ` Felipe Balbi
2013-02-17 3:09 ` Peter Chen [this message]
2013-02-26 18:21 ` Felipe Balbi
2013-02-27 3:10 ` Peter Chen
2013-02-27 8:42 ` Felipe Balbi
2013-02-27 8:57 ` Chen Peter-B29397
2013-02-14 12:15 ` [PATCH v8 0/8] Add tested id switch and vbus connect detect support for Chipidea Alexander Shishkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130217030951.GA1588@nchen-desktop \
--to=peter.chen@freescale.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox