--- initial
+++ final
@@ -1,156 +1,155 @@
 static int mv_u3d_probe(struct platform_device *dev) {
   struct mv_u3d *u3d = NULL;
   struct mv_usb_platform_data *pdata = dev->dev.platform_data;
   int retval = 0;
   struct resource *r;
   size_t size;
   if (!dev->dev.platform_data) {
     dev_err(&dev->dev, "missing platform_data\n");
     retval = -ENODEV;
     goto err_pdata;
   }
   u3d = kzalloc(sizeof(*u3d), GFP_KERNEL);
   if (!u3d) {
     dev_err(&dev->dev, "failed to allocate memory for u3d\n");
     retval = -ENOMEM;
     goto err_alloc_private;
   }
   spin_lock_init(&u3d->lock);
   platform_set_drvdata(dev, u3d);
   u3d->dev = &dev->dev;
   u3d->vbus = pdata->vbus;
   u3d->clk = clk_get(&dev->dev, NULL);
   if (IS_ERR(u3d->clk)) {
     retval = PTR_ERR(u3d->clk);
     goto err_get_clk;
   }
   r = platform_get_resource_byname(dev, IORESOURCE_MEM, "capregs");
   if (!r) {
     dev_err(&dev->dev, "no I/O memory resource defined\n");
     retval = -ENODEV;
     goto err_get_cap_regs;
   }
   u3d->cap_regs = (struct mv_u3d_cap_regs __iomem *)ioremap(r->start, resource_size(r));
   if (!u3d->cap_regs) {
     dev_err(&dev->dev, "failed to map I/O memory\n");
     retval = -EBUSY;
     goto err_map_cap_regs;
   } else {
     dev_dbg(&dev->dev, "cap_regs address: 0x%lx/0x%lx\n", (unsigned long)r->start, (unsigned long)u3d->cap_regs);
   }
   /* we will access controller register, so enable the u3d controller */
   clk_enable(u3d->clk);
   if (pdata->phy_init) {
     retval = pdata->phy_init(u3d->phy_regs);
     if (retval) {
       dev_err(&dev->dev, "init phy error %d\n", retval);
       goto err_u3d_enable;
     }
   }
   u3d->op_regs = (struct mv_u3d_op_regs __iomem *)(u3d->cap_regs + MV_U3D_USB3_OP_REGS_OFFSET);
   u3d->vuc_regs = (struct mv_u3d_vuc_regs __iomem *)(u3d->cap_regs + ioread32(&u3d->cap_regs->vuoff));
   u3d->max_eps = 16;
   /*
    * some platform will use usb to download image, it may not disconnect
    * usb gadget before loading kernel. So first stop u3d here.
    */
   mv_u3d_controller_stop(u3d);
   iowrite32(0xFFFFFFFF, &u3d->vuc_regs->intrcause);
   if (pdata->phy_deinit) pdata->phy_deinit(u3d->phy_regs);
   clk_disable(u3d->clk);
   size = u3d->max_eps * sizeof(struct mv_u3d_ep_context) * 2;
   size = (size + MV_U3D_EP_CONTEXT_ALIGNMENT - 1) & ~(MV_U3D_EP_CONTEXT_ALIGNMENT - 1);
   u3d->ep_context = dma_alloc_coherent(&dev->dev, size, &u3d->ep_context_dma, GFP_KERNEL);
   if (!u3d->ep_context) {
     dev_err(&dev->dev, "allocate ep context memory failed\n");
     retval = -ENOMEM;
     goto err_alloc_ep_context;
   }
   u3d->ep_context_size = size;
   /* create TRB dma_pool resource */
   u3d->trb_pool = dma_pool_create("u3d_trb", &dev->dev, sizeof(struct mv_u3d_trb_hw), MV_U3D_TRB_ALIGNMENT, MV_U3D_DMA_BOUNDARY);
   if (!u3d->trb_pool) {
     retval = -ENOMEM;
     goto err_alloc_trb_pool;
   }
   size = u3d->max_eps * sizeof(struct mv_u3d_ep) * 2;
   u3d->eps = kzalloc(size, GFP_KERNEL);
   if (!u3d->eps) {
     dev_err(&dev->dev, "allocate ep memory failed\n");
     retval = -ENOMEM;
     goto err_alloc_eps;
   }
   /* initialize ep0 status request structure */
   u3d->status_req = kzalloc(sizeof(struct mv_u3d_req) + 8, GFP_KERNEL);
   if (!u3d->status_req) {
     dev_err(&dev->dev, "allocate status_req memory failed\n");
     retval = -ENOMEM;
     goto err_alloc_status_req;
   }
   INIT_LIST_HEAD(&u3d->status_req->queue);
   /* allocate a small amount of memory to get valid address */
   u3d->status_req->req.buf = (char *)u3d->status_req + sizeof(struct mv_u3d_req);
   u3d->status_req->req.dma = virt_to_phys(u3d->status_req->req.buf);
   u3d->resume_state = USB_STATE_NOTATTACHED;
   u3d->usb_state = USB_STATE_ATTACHED;
   u3d->ep0_dir = MV_U3D_EP_DIR_OUT;
   u3d->remote_wakeup = 0;
   r = platform_get_resource(dev, IORESOURCE_IRQ, 0);
   if (!r) {
     dev_err(&dev->dev, "no IRQ resource defined\n");
     retval = -ENODEV;
     goto err_get_irq;
   }
   u3d->irq = r->start;
   if (request_irq(u3d->irq, mv_u3d_irq, IRQF_DISABLED | IRQF_SHARED, driver_name, u3d)) {
     u3d->irq = 0;
     dev_err(&dev->dev, "Request irq %d for u3d failed\n", u3d->irq);
     retval = -ENODEV;
     goto err_request_irq;
   }
   /* initialize gadget structure */
   u3d->gadget.ops = &mv_u3d_ops;         /* usb_gadget_ops */
   u3d->gadget.ep0 = &u3d->eps[1].ep;     /* gadget ep0 */
   INIT_LIST_HEAD(&u3d->gadget.ep_list);  /* ep_list */
   u3d->gadget.speed = USB_SPEED_UNKNOWN; /* speed */
   /* the "gadget" abstracts/virtualizes the controller */
   u3d->gadget.name = driver_name; /* gadget name */
   mv_u3d_eps_init(u3d);
   /* external vbus detection */
   if (u3d->vbus) {
     u3d->clock_gating = 1;
     dev_err(&dev->dev, "external vbus detection\n");
   }
   if (!u3d->clock_gating) u3d->vbus_active = 1;
   /* enable usb3 controller vbus detection */
   u3d->vbus_valid_detect = 1;
   retval = usb_add_gadget_udc(&dev->dev, &u3d->gadget);
   if (retval) goto err_unregister;
   dev_dbg(&dev->dev, "successful probe usb3 device %s clock gating.\n", u3d->clock_gating ? "with" : "without");
   return 0;
 err_unregister:
   free_irq(u3d->irq, &dev->dev);
 err_request_irq:
 err_get_irq:
   kfree(u3d->status_req);
 err_alloc_status_req:
   kfree(u3d->eps);
 err_alloc_eps:
   dma_pool_destroy(u3d->trb_pool);
 err_alloc_trb_pool:
   dma_free_coherent(&dev->dev, u3d->ep_context_size, u3d->ep_context, u3d->ep_context_dma);
 err_alloc_ep_context:
   if (pdata->phy_deinit) pdata->phy_deinit(u3d->phy_regs);
   clk_disable(u3d->clk);
 err_u3d_enable:
   iounmap(u3d->cap_regs);
 err_map_cap_regs:
 err_get_cap_regs:
 err_get_clk:
   clk_put(u3d->clk);
-  platform_set_drvdata(dev, NULL);
   kfree(u3d);
 err_alloc_private:
 err_pdata:
   return retval;
 }<sep>@@
expression dev;
@@

- platform_set_drvdata(dev, NULL);