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 <[email protected]>
> ---
> 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?
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().
Alan Stern
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html