linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Chen <peter.chen@nxp.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Roger Quadros <rogerq@ti.com>,
	USB mailing list <linux-usb@vger.kernel.org>
Subject: Re: Adding and removing the same gadget multiple times
Date: Thu, 30 Jul 2020 02:37:53 +0000	[thread overview]
Message-ID: <20200730023728.GB26224@b29397-desktop> (raw)
In-Reply-To: <20200729141448.GB1530967@rowland.harvard.edu>

On 20-07-29 10:14:48, Alan Stern wrote:
> On Wed, Jul 29, 2020 at 01:47:20AM +0000, Peter Chen wrote:
> > On 20-07-28 15:32:46, Alan Stern wrote:
> > > Roger:
> > > 
> > > Your commit fac323471df6 ("usb: udc: allow adding and removing the same 
> > > gadget device") from a few years ago just caught my eye.  (I don't 
> > > recall whether I noticed it at the time.)
> > > 
> > > In any case, we need to talk about it.  What you're doing -- 
> > > unregistering and re-registering the struct device embedded in the 
> > > gadget structure -- is strictly forbidden by the kernel's device model. 
> > > It's even mentioned specifically in the kerneldoc for device_add().
> > > 
> > > Now, I guess doing this would be okay _if_ you took care not to 
> > > re-register the device until all references to the previous incarnation 
> > > have been dropped.  In particular, setting the structure's memory to 0 
> > > should not be done immediately after calling device_unregister() -- 
> > > which is what the commit does -- but rather in the release routine.
> > > 
> > > Do you know which UDC drivers actually do re-register their gadgets?  In 
> > > particular, do they have their own release routines or do they rely on 
> > > the default usb_udc_nop_release() provided by the UDC core?
> > 
> > dwc3 and cdns3 gadget driver do that, they use default usb_udc_nop_release()
> > provided by the UDC core. The usb_add_gadget_udc is called when the
> > controller role switch to device mode (the host VBUS is seen at device
> > side), and usb_del_gadget_udc is called when the cable is disconnected
> > from host.
> 
> What if the role switches back to host without the cable being
> disconnected?

This kinds of role switch is through the sys entry directly, without
considering hardware signal. Taking cdns3 as an example for this use
case, usb_del_gadget_udc will be called for stopping device mode, and
create xhci platform device for starting host.

-- 

Thanks,
Peter Chen

      parent reply	other threads:[~2020-07-30  2:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-28 19:32 Adding and removing the same gadget multiple times Alan Stern
2020-07-29  1:47 ` Peter Chen
2020-07-29 14:14   ` Alan Stern
2020-07-29 14:19     ` Greg KH
2020-07-30  2:37     ` Peter Chen [this message]

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=20200730023728.GB26224@b29397-desktop \
    --to=peter.chen@nxp.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=rogerq@ti.com \
    --cc=stern@rowland.harvard.edu \
    /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;
as well as URLs for NNTP newsgroup(s).