The removal cleanup code is duplicated between the different bus glues.
Move it to a central location.

Signed-off-by: Laurent Pinchart <[email protected]>
---
 drivers/usb/host/isp1760-hcd.c | 15 ++++++++
 drivers/usb/host/isp1760-hcd.h |  2 ++
 drivers/usb/host/isp1760-if.c  | 80 ++++++++++++------------------------------
 3 files changed, 39 insertions(+), 58 deletions(-)

diff --git a/drivers/usb/host/isp1760-hcd.c b/drivers/usb/host/isp1760-hcd.c
index 51a0ae9..281de5e 100644
--- a/drivers/usb/host/isp1760-hcd.c
+++ b/drivers/usb/host/isp1760-hcd.c
@@ -2263,6 +2263,21 @@ err_put:
         return ERR_PTR(ret);
 }
 
+void isp1760_unregister(struct device *dev)
+{
+       struct usb_hcd *hcd = dev_get_drvdata(dev);
+       struct isp1760_hcd *priv = hcd_to_priv(hcd);
+
+       release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
+
+       usb_remove_hcd(hcd);
+       iounmap(hcd->regs);
+       usb_put_hcd(hcd);
+
+       if (gpio_is_valid(priv->rst_gpio))
+               gpio_free(priv->rst_gpio);
+}
+
 MODULE_DESCRIPTION("Driver for the ISP1760 USB-controller from NXP");
 MODULE_AUTHOR("Sebastian Siewior <[email protected]>");
 MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/host/isp1760-hcd.h b/drivers/usb/host/isp1760-hcd.h
index 33dc79c..3538b27 100644
--- a/drivers/usb/host/isp1760-hcd.h
+++ b/drivers/usb/host/isp1760-hcd.h
@@ -7,6 +7,8 @@ struct usb_hcd *isp1760_register(phys_addr_t res_start, 
resource_size_t res_len,
                                 int rst_gpio,
                                 struct device *dev, const char *busname,
                                 unsigned int devflags);
+void isp1760_unregister(struct device *dev);
+
 int init_kmem_once(void);
 void deinit_kmem_cache(void);
 
diff --git a/drivers/usb/host/isp1760-if.c b/drivers/usb/host/isp1760-if.c
index 4da0c49..42e0884 100644
--- a/drivers/usb/host/isp1760-if.c
+++ b/drivers/usb/host/isp1760-if.c
@@ -32,14 +32,9 @@
 #endif
 
 #if defined(CONFIG_OF) && defined(CONFIG_OF_IRQ)
-struct isp1760 {
-       struct usb_hcd *hcd;
-       int rst_gpio;
-};
-
 static int of_isp1760_probe(struct platform_device *dev)
 {
-       struct isp1760 *drvdata;
+       struct usb_hcd *hcd;
        struct device_node *dp = dev->dev.of_node;
        struct resource *res;
        struct resource memory;
@@ -49,24 +44,17 @@ static int of_isp1760_probe(struct platform_device *dev)
        unsigned int devflags = 0;
        enum of_gpio_flags gpio_flags;
        u32 bus_width = 0;
-
-       drvdata = kzalloc(sizeof(*drvdata), GFP_KERNEL);
-       if (!drvdata)
-               return -ENOMEM;
+       int rst_gpio;
 
        ret = of_address_to_resource(dp, 0, &memory);
-       if (ret) {
-               ret = -ENXIO;
-               goto free_data;
-       }
+       if (ret)
+               return -ENXIO;
 
        res_len = resource_size(&memory);
 
        res = request_mem_region(memory.start, res_len, dev_name(&dev->dev));
-       if (!res) {
-               ret = -EBUSY;
-               goto free_data;
-       }
+       if (!res)
+               return -EBUSY;
 
        virq = irq_of_parse_and_map(dp, 0);
        if (!virq) {
@@ -94,56 +82,45 @@ static int of_isp1760_probe(struct platform_device *dev)
        if (of_get_property(dp, "dreq-polarity", NULL) != NULL)
                devflags |= ISP1760_FLAG_DREQ_POL_HIGH;
 
-       drvdata->rst_gpio = of_get_gpio_flags(dp, 0, &gpio_flags);
-       if (gpio_is_valid(drvdata->rst_gpio)) {
-               ret = gpio_request(drvdata->rst_gpio, dev_name(&dev->dev));
+       rst_gpio = of_get_gpio_flags(dp, 0, &gpio_flags);
+       if (gpio_is_valid(rst_gpio)) {
+               ret = gpio_request(rst_gpio, dev_name(&dev->dev));
                if (!ret) {
                        if (!(gpio_flags & OF_GPIO_ACTIVE_LOW)) {
                                devflags |= ISP1760_FLAG_RESET_ACTIVE_HIGH;
-                               gpio_direction_output(drvdata->rst_gpio, 0);
+                               gpio_direction_output(rst_gpio, 0);
                        } else {
-                               gpio_direction_output(drvdata->rst_gpio, 1);
+                               gpio_direction_output(rst_gpio, 1);
                        }
                } else {
-                       drvdata->rst_gpio = ret;
+                       rst_gpio = ret;
                }
        }
 
-       drvdata->hcd = isp1760_register(memory.start, res_len, virq,
-                                       IRQF_SHARED, drvdata->rst_gpio,
+       hcd = isp1760_register(memory.start, res_len, virq,
+                                       IRQF_SHARED, rst_gpio,
                                        &dev->dev, dev_name(&dev->dev),
                                        devflags);
-       if (IS_ERR(drvdata->hcd)) {
-               ret = PTR_ERR(drvdata->hcd);
+       if (IS_ERR(hcd)) {
+               ret = PTR_ERR(hcd);
                goto free_gpio;
        }
 
-       platform_set_drvdata(dev, drvdata);
+       platform_set_drvdata(dev, hcd);
        return ret;
 
 free_gpio:
-       if (gpio_is_valid(drvdata->rst_gpio))
-               gpio_free(drvdata->rst_gpio);
+       if (gpio_is_valid(rst_gpio))
+               gpio_free(rst_gpio);
 release_reg:
        release_mem_region(memory.start, res_len);
-free_data:
-       kfree(drvdata);
        return ret;
 }
 
 static int of_isp1760_remove(struct platform_device *dev)
 {
-       struct isp1760 *drvdata = platform_get_drvdata(dev);
-
-       usb_remove_hcd(drvdata->hcd);
-       iounmap(drvdata->hcd->regs);
-       release_mem_region(drvdata->hcd->rsrc_start, drvdata->hcd->rsrc_len);
-       usb_put_hcd(drvdata->hcd);
+       isp1760_unregister(&dev->dev);
 
-       if (gpio_is_valid(drvdata->rst_gpio))
-               gpio_free(drvdata->rst_gpio);
-
-       kfree(drvdata);
        return 0;
 }
 
@@ -305,14 +282,7 @@ cleanup1:
 
 static void isp1761_pci_remove(struct pci_dev *dev)
 {
-       struct usb_hcd *hcd;
-
-       hcd = pci_get_drvdata(dev);
-
-       usb_remove_hcd(hcd);
-       iounmap(hcd->regs);
-       release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
-       usb_put_hcd(hcd);
+       isp1760_unregister(&dev->dev);
 
        pci_disable_device(dev);
 }
@@ -415,13 +385,7 @@ out:
 
 static int isp1760_plat_remove(struct platform_device *pdev)
 {
-       struct usb_hcd *hcd = platform_get_drvdata(pdev);
-
-       usb_remove_hcd(hcd);
-
-       release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
-
-       usb_put_hcd(hcd);
+       isp1760_unregister(&pdev->dev);
 
        return 0;
 }
-- 
2.0.4

--
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

Reply via email to