Skip to content

Commit

Permalink
usb: gadget: imx_udc: fix gadget->dev registration
Browse files Browse the repository at this point in the history
Whenever ->udc_start() gets called, gadget driver
has already being bound to the udc controller, which
means that gadget->dev had to be already initialized
and added to driver model.

This patch fixes imx_udc mistake.

Signed-off-by: Felipe Balbi <balbi@ti.com>
  • Loading branch information
Felipe Balbi committed Mar 4, 2013
1 parent 9992a99 commit bc530a7
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions drivers/usb/gadget/imx_udc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1334,27 +1334,18 @@ static int imx_udc_start(struct usb_gadget *gadget,
struct usb_gadget_driver *driver)
{
struct imx_udc_struct *imx_usb;
int retval;

imx_usb = container_of(gadget, struct imx_udc_struct, gadget);
/* first hook up the driver ... */
imx_usb->driver = driver;
imx_usb->gadget.dev.driver = &driver->driver;

retval = device_add(&imx_usb->gadget.dev);
if (retval)
goto fail;

D_INI(imx_usb->dev, "<%s> registered gadget driver '%s'\n",
__func__, driver->driver.name);

imx_udc_enable(imx_usb);

return 0;
fail:
imx_usb->driver = NULL;
imx_usb->gadget.dev.driver = NULL;
return retval;
}

static int imx_udc_stop(struct usb_gadget *gadget,
Expand All @@ -1370,8 +1361,6 @@ static int imx_udc_stop(struct usb_gadget *gadget,
imx_usb->gadget.dev.driver = NULL;
imx_usb->driver = NULL;

device_del(&imx_usb->gadget.dev);

D_INI(imx_usb->dev, "<%s> unregistered gadget driver '%s'\n",
__func__, driver->driver.name);

Expand Down Expand Up @@ -1477,6 +1466,10 @@ static int __init imx_udc_probe(struct platform_device *pdev)
imx_usb->gadget.dev.parent = &pdev->dev;
imx_usb->gadget.dev.dma_mask = pdev->dev.dma_mask;

ret = device_add(&imx_usb->gadget.dev);
if (retval)
goto fail4;

platform_set_drvdata(pdev, imx_usb);

usb_init_data(imx_usb);
Expand All @@ -1488,9 +1481,11 @@ static int __init imx_udc_probe(struct platform_device *pdev)

ret = usb_add_gadget_udc(&pdev->dev, &imx_usb->gadget);
if (ret)
goto fail4;
goto fail5;

return 0;
fail5:
device_unregister(&imx_usb->gadget.dev);
fail4:
for (i = 0; i < IMX_USB_NB_EP + 1; i++)
free_irq(imx_usb->usbd_int[i], imx_usb);
Expand All @@ -1514,6 +1509,7 @@ static int __exit imx_udc_remove(struct platform_device *pdev)
int i;

usb_del_gadget_udc(&imx_usb->gadget);
device_unregister(&imx_usb->gadget.dev);
imx_udc_disable(imx_usb);
del_timer(&imx_usb->timer);

Expand Down

0 comments on commit bc530a7

Please sign in to comment.