Re: [PATCH v3 1/3] usb: udc: add usb_gadget_find_udc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jan 16, 2015 at 10:15:45AM -0600, Felipe Balbi wrote:
> On Fri, Jan 16, 2015 at 11:05:07AM -0500, Alan Stern wrote:
> > On Fri, 16 Jan 2015, Peter Chen wrote:
> > 
> > > This is an internal API, and is used to find corresponding udc according
> > > to gadget.
> > > 
> > > Signed-off-by: Peter Chen <peter.chen@xxxxxxxxxxxxx>
> > > ---
> > >  drivers/usb/gadget/udc/udc-core.c | 51 ++++++++++++++++++++-------------------
> > >  1 file changed, 26 insertions(+), 25 deletions(-)
> > > 
> > > diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c
> > > index e31d574..36c58c9 100644
> > > --- a/drivers/usb/gadget/udc/udc-core.c
> > > +++ b/drivers/usb/gadget/udc/udc-core.c
> > > @@ -52,6 +52,25 @@ static DEFINE_MUTEX(udc_lock);
> > >  
> > >  /* ------------------------------------------------------------------------- */
> > >  
> > > +static struct usb_udc *usb_gadget_find_udc(struct usb_gadget *gadget)
> > > +{
> > > +	struct usb_udc		*udc = NULL;
> > > +
> > > +	mutex_lock(&udc_lock);
> > > +	list_for_each_entry(udc, &udc_list, list)
> > > +		if (udc->gadget == gadget)
> > > +			goto found;
> > > +	mutex_unlock(&udc_lock);
> > > +	dev_err(gadget->dev.parent, "gadget not registered.\n");
> > > +
> > > +	return NULL;
> > > +
> > > +found:
> > > +	mutex_unlock(&udc_lock);
> > > +	return udc;
> > > +}
> > 
> > An idea just struck me...  Instead of looping through all the udc's to
> > find the right one, why not simply store a pointer to the udc in struct
> > usb_gadget?
> > 

We still have code to find usb_gadget_driver to iterate udc_list, it
is better to change all, we need to have solution to consolidate
struct usb_udc, struct usb_gadget, and struct usb_gadget_drver.
I have no good solution now.

> > Also, it looks like there's a bug in usb_add_gadget_udc_release() in 
> > udc-core.c.  The error pathway (between err3 and err2) does not undo 
> > the
> > 
> > 	ret = device_register(&gadget->dev);
> > 
> > call.  There's a put_device() call but no device_del().
> 
> good point :-) Do you want to send a patch for that ?
> 

It looks like there is another issue in error pathway, the
put_device(&udc->dev) at err3 should be moved to err4 since
the get_device is called at device_add.

-- 

Best Regards,
Peter Chen
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux