From patchwork Sun Feb 17 03:09:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 2152801 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id D98E63FD4F for ; Sun, 17 Feb 2013 03:13:32 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1U6udv-0002sw-KW; Sun, 17 Feb 2013 03:10:19 +0000 Received: from db3ehsobe005.messaging.microsoft.com ([213.199.154.143] helo=db3outboundpool.messaging.microsoft.com) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1U6uds-0002sc-Je for linux-arm-kernel@lists.infradead.org; Sun, 17 Feb 2013 03:10:17 +0000 Received: from mail44-db3-R.bigfish.com (10.3.81.244) by DB3EHSOBE006.bigfish.com (10.3.84.26) with Microsoft SMTP Server id 14.1.225.23; Sun, 17 Feb 2013 03:10:14 +0000 Received: from mail44-db3 (localhost [127.0.0.1]) by mail44-db3-R.bigfish.com (Postfix) with ESMTP id 461613402A6; Sun, 17 Feb 2013 03:10:14 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: -2 X-BigFish: VS-2(zz98dI1432Izz1f42h1ee6h1de0h1202h1e76h1d1ah1d2ahzz8275bhz2dh2a8h668h839h944hd25hd2bhf0ah1220h1288h12a5h12a9h12bdh137ah13b6h1441h1504h1537h153bh162dh1631h1758h18e1h1946h19b5h1155h) Received: from mail44-db3 (localhost.localdomain [127.0.0.1]) by mail44-db3 (MessageSwitch) id 1361070612249427_27152; Sun, 17 Feb 2013 03:10:12 +0000 (UTC) Received: from DB3EHSMHS004.bigfish.com (unknown [10.3.81.241]) by mail44-db3.bigfish.com (Postfix) with ESMTP id 2F52916007A; Sun, 17 Feb 2013 03:10:12 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by DB3EHSMHS004.bigfish.com (10.3.87.104) with Microsoft SMTP Server (TLS) id 14.1.225.23; Sun, 17 Feb 2013 03:10:12 +0000 Received: from az84smr01.freescale.net (10.64.34.197) by 039-SN1MMR1-001.039d.mgd.msft.net (10.84.1.13) with Microsoft SMTP Server (TLS) id 14.2.328.11; Sun, 17 Feb 2013 03:10:10 +0000 Received: from nchen-desktop (nchen-desktop.ap.freescale.net [10.192.242.40]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id r1H39sr9008769; Sat, 16 Feb 2013 20:09:56 -0700 Date: Sun, 17 Feb 2013 11:09:53 +0800 From: Peter Chen To: Felipe Balbi Subject: Re: [PATCH v8 8/8] usb: chipidea: udc: fix the oops when plugs in usb cable after rmmod gadget Message-ID: <20130217030951.GA1588@nchen-desktop> References: <1360051215-27722-1-git-send-email-peter.chen@freescale.com> <1360051215-27722-9-git-send-email-peter.chen@freescale.com> <20130213084128.GB2426@arwen.pp.htv.fi> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20130213084128.GB2426@arwen.pp.htv.fi> User-Agent: Mutt/1.5.20 (2009-06-14) X-OriginatorOrg: freescale.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130216_221016_864715_07F8E983 X-CRM114-Status: GOOD ( 16.41 ) X-Spam-Score: 0.4 (/) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (0.4 points) pts rule name description ---- ---------------------- -------------------------------------------------- 3.0 KHOP_BIG_TO_CC Sent to 10+ recipients instaed of Bcc or a list -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [213.199.154.143 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: marex@denx.de, m.grzeschik@pengutronix.de, gregkh@linuxfoundation.org, alexander.shishkin@linux.intel.com, pkondeti@codeaurora.org, linux-usb@vger.kernel.org, mkl@pengutronix.de, kernel@pengutronix.de, matt@genesi-usa.com, shawn.guo@linaro.org, festevam@gmail.com, linux-arm-kernel@lists.infradead.org, linuxzsc@gmail.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org On Wed, Feb 13, 2013 at 10:41:28AM +0200, Felipe Balbi wrote: > Hi, > > > > > Signed-off-by: Peter Chen > > > > 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;