usb: musb: remove hand-crafted id handling
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Wed, 31 Oct 2012 15:12:43 +0000 (16:12 +0100)
committerFelipe Balbi <balbi@ti.com>
Thu, 1 Nov 2012 10:32:23 +0000 (12:32 +0200)
This replaced the handcrafted id handling by the PLATFORM_DEVID_AUTO
value which should do the same thing.

This patch probably also fixes ux500 because I did not find the "musbid"
variable to remove. And we close a tiny-unlikely race window becuase the
old code gave the id back before device was destroyed in the remove
case.

[ balbi@ti.com : fixed up two failed hunks when applying patch ]

Cc: B, Ravi <ravibabu@ti.com>
Cc: Santhapuri, Damodar <damodar.santhapuri@ti.com>
Cc: Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>
Cc: Bob Liu <lliubbo@gmail.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
drivers/usb/musb/am35x.c
drivers/usb/musb/blackfin.c
drivers/usb/musb/da8xx.c
drivers/usb/musb/davinci.c
drivers/usb/musb/musb_core.c
drivers/usb/musb/musb_core.h
drivers/usb/musb/musb_dsps.c
drivers/usb/musb/omap2430.c
drivers/usb/musb/tusb6010.c
drivers/usb/musb/ux500.c

index fdfd779c35b3658e6734ba943a8734b85f732488..3ff30b9a58949bb6407a2681c6f71f8081bb4268 100644 (file)
@@ -459,7 +459,6 @@ static int __devinit am35x_probe(struct platform_device *pdev)
        struct clk                      *clk;
 
        int                             ret = -ENOMEM;
-       int                             musbid;
 
        glue = kzalloc(sizeof(*glue), GFP_KERNEL);
        if (!glue) {
@@ -467,18 +466,10 @@ static int __devinit am35x_probe(struct platform_device *pdev)
                goto err0;
        }
 
-       /* get the musb id */
-       musbid = musb_get_id(&pdev->dev, GFP_KERNEL);
-       if (musbid < 0) {
-               dev_err(&pdev->dev, "failed to allocate musb id\n");
-               ret = -ENOMEM;
-               goto err1;
-       }
-
-       musb = platform_device_alloc("musb-hdrc", musbid);
+       musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
        if (!musb) {
                dev_err(&pdev->dev, "failed to allocate musb device\n");
-               goto err2;
+               goto err1;
        }
 
        phy_clk = clk_get(&pdev->dev, "fck");
@@ -507,7 +498,6 @@ static int __devinit am35x_probe(struct platform_device *pdev)
                goto err6;
        }
 
-       musb->id                        = musbid;
        musb->dev.parent                = &pdev->dev;
        musb->dev.dma_mask              = &am35x_dmamask;
        musb->dev.coherent_dma_mask     = am35x_dmamask;
@@ -557,9 +547,6 @@ err4:
 err3:
        platform_device_put(musb);
 
-err2:
-       musb_put_id(&pdev->dev, musbid);
-
 err1:
        kfree(glue);
 
@@ -571,7 +558,6 @@ static int __devexit am35x_remove(struct platform_device *pdev)
 {
        struct am35x_glue       *glue = platform_get_drvdata(pdev);
 
-       musb_put_id(&pdev->dev, glue->musb->id);
        platform_device_unregister(glue->musb);
        clk_disable(glue->clk);
        clk_disable(glue->phy_clk);
index 307e726a2bd7e47b8e912dd59da161717dad2b73..7e4d60a41728090e35f7eba33b7cdd62887fd2b8 100644 (file)
@@ -455,7 +455,6 @@ static int __devinit bfin_probe(struct platform_device *pdev)
        struct bfin_glue                *glue;
 
        int                             ret = -ENOMEM;
-       int                             musbid;
 
        glue = kzalloc(sizeof(*glue), GFP_KERNEL);
        if (!glue) {
@@ -463,21 +462,12 @@ static int __devinit bfin_probe(struct platform_device *pdev)
                goto err0;
        }
 
-       /* get the musb id */
-       musbid = musb_get_id(&pdev->dev, GFP_KERNEL);
-       if (musbid < 0) {
-               dev_err(&pdev->dev, "failed to allocate musb id\n");
-               ret = -ENOMEM;
-               goto err1;
-       }
-
-       musb = platform_device_alloc("musb-hdrc", musbid);
+       musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
        if (!musb) {
                dev_err(&pdev->dev, "failed to allocate musb device\n");
-               goto err2;
+               goto err1;
        }
 
-       musb->id                        = musbid;
        musb->dev.parent                = &pdev->dev;
        musb->dev.dma_mask              = &bfin_dmamask;
        musb->dev.coherent_dma_mask     = bfin_dmamask;
@@ -513,9 +503,6 @@ static int __devinit bfin_probe(struct platform_device *pdev)
 err3:
        platform_device_put(musb);
 
-err2:
-       musb_put_id(&pdev->dev, musbid);
-
 err1:
        kfree(glue);
 
@@ -527,7 +514,6 @@ static int __devexit bfin_remove(struct platform_device *pdev)
 {
        struct bfin_glue                *glue = platform_get_drvdata(pdev);
 
-       musb_put_id(&pdev->dev, glue->musb->id);
        platform_device_unregister(glue->musb);
        kfree(glue);
 
index e94f556c6aea152c7069ac19b85b575cc0f7e73b..67b8ae704e9a93ac45536ba4820515e44725ed5d 100644 (file)
@@ -480,7 +480,6 @@ static int __devinit da8xx_probe(struct platform_device *pdev)
        struct clk                      *clk;
 
        int                             ret = -ENOMEM;
-       int                             musbid;
 
        glue = kzalloc(sizeof(*glue), GFP_KERNEL);
        if (!glue) {
@@ -488,18 +487,10 @@ static int __devinit da8xx_probe(struct platform_device *pdev)
                goto err0;
        }
 
-       /* get the musb id */
-       musbid = musb_get_id(&pdev->dev, GFP_KERNEL);
-       if (musbid < 0) {
-               dev_err(&pdev->dev, "failed to allocate musb id\n");
-               ret = -ENOMEM;
-               goto err1;
-       }
-
-       musb = platform_device_alloc("musb-hdrc", musbid);
+       musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
        if (!musb) {
                dev_err(&pdev->dev, "failed to allocate musb device\n");
-               goto err2;
+               goto err1;
        }
 
        clk = clk_get(&pdev->dev, "usb20");
@@ -515,7 +506,6 @@ static int __devinit da8xx_probe(struct platform_device *pdev)
                goto err4;
        }
 
-       musb->id                        = musbid;
        musb->dev.parent                = &pdev->dev;
        musb->dev.dma_mask              = &da8xx_dmamask;
        musb->dev.coherent_dma_mask     = da8xx_dmamask;
@@ -558,9 +548,6 @@ err4:
 err3:
        platform_device_put(musb);
 
-err2:
-       musb_put_id(&pdev->dev, musbid);
-
 err1:
        kfree(glue);
 
@@ -572,7 +559,6 @@ static int __devexit da8xx_remove(struct platform_device *pdev)
 {
        struct da8xx_glue               *glue = platform_get_drvdata(pdev);
 
-       musb_put_id(&pdev->dev, glue->musb->id);
        platform_device_unregister(glue->musb);
        clk_disable(glue->clk);
        clk_put(glue->clk);
index 959a6d71e1d518388f14b9c807028b1c40187e0f..b3c0a943950c63c10f50979d8d4b1f4ac7afca75 100644 (file)
@@ -512,7 +512,6 @@ static int __devinit davinci_probe(struct platform_device *pdev)
        struct clk                      *clk;
 
        int                             ret = -ENOMEM;
-       int                             musbid;
 
        glue = kzalloc(sizeof(*glue), GFP_KERNEL);
        if (!glue) {
@@ -520,18 +519,10 @@ static int __devinit davinci_probe(struct platform_device *pdev)
                goto err0;
        }
 
-       /* get the musb id */
-       musbid = musb_get_id(&pdev->dev, GFP_KERNEL);
-       if (musbid < 0) {
-               dev_err(&pdev->dev, "failed to allocate musb id\n");
-               ret = -ENOMEM;
-               goto err1;
-       }
-
-       musb = platform_device_alloc("musb-hdrc", musbid);
+       musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
        if (!musb) {
                dev_err(&pdev->dev, "failed to allocate musb device\n");
-               goto err2;
+               goto err1;
        }
 
        clk = clk_get(&pdev->dev, "usb");
@@ -547,7 +538,6 @@ static int __devinit davinci_probe(struct platform_device *pdev)
                goto err4;
        }
 
-       musb->id                        = musbid;
        musb->dev.parent                = &pdev->dev;
        musb->dev.dma_mask              = &davinci_dmamask;
        musb->dev.coherent_dma_mask     = davinci_dmamask;
@@ -590,9 +580,6 @@ err4:
 err3:
        platform_device_put(musb);
 
-err2:
-       musb_put_id(&pdev->dev, musbid);
-
 err1:
        kfree(glue);
 
@@ -604,7 +591,6 @@ static int __devexit davinci_remove(struct platform_device *pdev)
 {
        struct davinci_glue             *glue = platform_get_drvdata(pdev);
 
-       musb_put_id(&pdev->dev, glue->musb->id);
        platform_device_unregister(glue->musb);
        clk_disable(glue->clk);
        clk_put(glue->clk);
index 25a0d8e1be515a1a6683116851bfac41b0917b1e..78037bfad96e95cc42a61d3f2c15ac52506db99b 100644 (file)
 
 #define MUSB_DRIVER_NAME "musb-hdrc"
 const char musb_driver_name[] = MUSB_DRIVER_NAME;
-static DEFINE_IDA(musb_ida);
 
 MODULE_DESCRIPTION(DRIVER_INFO);
 MODULE_AUTHOR(DRIVER_AUTHOR);
@@ -133,35 +132,6 @@ static inline struct musb *dev_to_musb(struct device *dev)
 
 /*-------------------------------------------------------------------------*/
 
-int musb_get_id(struct device *dev, gfp_t gfp_mask)
-{
-       int ret;
-       int id;
-
-       ret = ida_pre_get(&musb_ida, gfp_mask);
-       if (!ret) {
-               dev_err(dev, "failed to reserve resource for id\n");
-               return -ENOMEM;
-       }
-
-       ret = ida_get_new(&musb_ida, &id);
-       if (ret < 0) {
-               dev_err(dev, "failed to allocate a new id\n");
-               return ret;
-       }
-
-       return id;
-}
-EXPORT_SYMBOL_GPL(musb_get_id);
-
-void musb_put_id(struct device *dev, int id)
-{
-
-       dev_dbg(dev, "removing id %d\n", id);
-       ida_remove(&musb_ida, id);
-}
-EXPORT_SYMBOL_GPL(musb_put_id);
-
 #ifndef CONFIG_BLACKFIN
 static int musb_ulpi_read(struct usb_phy *phy, u32 offset)
 {
index 0cef3ceb52c33a891a6c2c214a7ac283af7f444e..7fb4819a6f115f54d097ef09eb131fb820994d05 100644 (file)
@@ -522,8 +522,6 @@ extern const char musb_driver_name[];
 
 extern void musb_start(struct musb *musb);
 extern void musb_stop(struct musb *musb);
-extern int musb_get_id(struct device *dev, gfp_t gfp_mask);
-extern void musb_put_id(struct device *dev, int id);
 
 extern void musb_write_fifo(struct musb_hw_ep *ep, u16 len, const u8 *src);
 extern void musb_read_fifo(struct musb_hw_ep *ep, u16 len, u8 *dst);
index 828d2a216d9456efc1c0504432fde0add6081090..2d2cd37bc7ba0d9854680061c86339b03394a726 100644 (file)
@@ -459,7 +459,7 @@ static int __devinit dsps_create_musb_pdev(struct dsps_glue *glue, u8 id)
        struct resource *res;
        struct resource resources[2];
        char res_name[10];
-       int ret, musbid;
+       int ret;
 
        /* get memory resource */
        sprintf(res_name, "musb%d", id);
@@ -484,22 +484,14 @@ static int __devinit dsps_create_musb_pdev(struct dsps_glue *glue, u8 id)
        resources[1] = *res;
        resources[1].name = "mc";
 
-       /* get the musb id */
-       musbid = musb_get_id(dev, GFP_KERNEL);
-       if (musbid < 0) {
-               dev_err(dev, "failed to allocate musb id\n");
-               ret = -ENOMEM;
-               goto err0;
-       }
        /* allocate the child platform device */
-       musb = platform_device_alloc("musb-hdrc", musbid);
+       musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
        if (!musb) {
                dev_err(dev, "failed to allocate musb device\n");
                ret = -ENOMEM;
-               goto err1;
+               goto err0;
        }
 
-       musb->id                        = musbid;
        musb->dev.parent                = dev;
        musb->dev.dma_mask              = &musb_dmamask;
        musb->dev.coherent_dma_mask     = musb_dmamask;
@@ -556,18 +548,10 @@ static int __devinit dsps_create_musb_pdev(struct dsps_glue *glue, u8 id)
 
 err2:
        platform_device_put(musb);
-err1:
-       musb_put_id(dev, musbid);
 err0:
        return ret;
 }
 
-static void dsps_delete_musb_pdev(struct dsps_glue *glue, u8 id)
-{
-       musb_put_id(glue->dev, glue->musb[id]->id);
-       platform_device_unregister(glue->musb[id]);
-}
-
 static int __devinit dsps_probe(struct platform_device *pdev)
 {
        struct device_node *np = pdev->dev.of_node;
@@ -627,7 +611,7 @@ static int __devinit dsps_probe(struct platform_device *pdev)
                        dev_err(&pdev->dev, "failed to create child pdev\n");
                        /* release resources of previously created instances */
                        for (i--; i >= 0 ; i--)
-                               dsps_delete_musb_pdev(glue, i);
+                               platform_device_unregister(glue->musb[i]);
                        goto err3;
                }
        }
@@ -652,7 +636,7 @@ static int __devexit dsps_remove(struct platform_device *pdev)
 
        /* delete the child platform device */
        for (i = 0; i < wrp->instances ; i++)
-               dsps_delete_musb_pdev(glue, i);
+               platform_device_unregister(glue->musb[i]);
 
        /* disable usbss clocks */
        pm_runtime_put(&pdev->dev);
index a538fe17a966b0932400a3be02087be1aec5f26c..dddd8f71a17663ce903c73515a81ceb3516da8be 100644 (file)
@@ -478,7 +478,6 @@ static int __devinit omap2430_probe(struct platform_device *pdev)
        struct musb_hdrc_config         *config;
        struct resource                 *res;
        int                             ret = -ENOMEM;
-       int                             musbid;
 
        glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
        if (!glue) {
@@ -486,21 +485,12 @@ static int __devinit omap2430_probe(struct platform_device *pdev)
                goto err0;
        }
 
-       /* get the musb id */
-       musbid = musb_get_id(&pdev->dev, GFP_KERNEL);
-       if (musbid < 0) {
-               dev_err(&pdev->dev, "failed to allocate musb id\n");
-               ret = -ENOMEM;
-               goto err0;
-       }
-
-       musb = platform_device_alloc("musb-hdrc", musbid);
+       musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
        if (!musb) {
                dev_err(&pdev->dev, "failed to allocate musb device\n");
-               goto err1;
+               goto err0;
        }
 
-       musb->id                        = musbid;
        musb->dev.parent                = &pdev->dev;
        musb->dev.dma_mask              = &omap2430_dmamask;
        musb->dev.coherent_dma_mask     = omap2430_dmamask;
@@ -521,7 +511,7 @@ static int __devinit omap2430_probe(struct platform_device *pdev)
                        dev_err(&pdev->dev,
                                "failed to allocate musb platfrom data\n");
                        ret = -ENOMEM;
-                       goto err1;
+                       goto err2;
                }
 
                data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
@@ -529,14 +519,14 @@ static int __devinit omap2430_probe(struct platform_device *pdev)
                        dev_err(&pdev->dev,
                                        "failed to allocate musb board data\n");
                        ret = -ENOMEM;
-                       goto err1;
+                       goto err2;
                }
 
                config = devm_kzalloc(&pdev->dev, sizeof(*config), GFP_KERNEL);
                if (!data) {
                        dev_err(&pdev->dev,
                                "failed to allocate musb hdrc config\n");
-                       goto err1;
+                       goto err2;
                }
 
                of_property_read_u32(np, "mode", (u32 *)&pdata->mode);
@@ -589,9 +579,6 @@ static int __devinit omap2430_probe(struct platform_device *pdev)
 err2:
        platform_device_put(musb);
 
-err1:
-       musb_put_id(&pdev->dev, musbid);
-
 err0:
        return ret;
 }
@@ -601,7 +588,6 @@ static int __devexit omap2430_remove(struct platform_device *pdev)
        struct omap2430_glue            *glue = platform_get_drvdata(pdev);
 
        cancel_work_sync(&glue->omap_musb_mailbox_work);
-       musb_put_id(&pdev->dev, glue->musb->id);
        platform_device_unregister(glue->musb);
 
        return 0;
index 4454561c6f57453d33e248749fdde79f6dcaf93a..812719b683d1a858a976f31aa4efd4af6f3ad494 100644 (file)
@@ -1160,7 +1160,6 @@ static int __devinit tusb_probe(struct platform_device *pdev)
        struct tusb6010_glue            *glue;
 
        int                             ret = -ENOMEM;
-       int                             musbid;
 
        glue = kzalloc(sizeof(*glue), GFP_KERNEL);
        if (!glue) {
@@ -1168,21 +1167,12 @@ static int __devinit tusb_probe(struct platform_device *pdev)
                goto err0;
        }
 
-       /* get the musb id */
-       musbid = musb_get_id(&pdev->dev, GFP_KERNEL);
-       if (musbid < 0) {
-               dev_err(&pdev->dev, "failed to allocate musb id\n");
-               ret = -ENOMEM;
-               goto err1;
-       }
-
-       musb = platform_device_alloc("musb-hdrc", musbid);
+       musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
        if (!musb) {
                dev_err(&pdev->dev, "failed to allocate musb device\n");
-               goto err2;
+               goto err1;
        }
 
-       musb->id                        = musbid;
        musb->dev.parent                = &pdev->dev;
        musb->dev.dma_mask              = &tusb_dmamask;
        musb->dev.coherent_dma_mask     = tusb_dmamask;
@@ -1218,9 +1208,6 @@ static int __devinit tusb_probe(struct platform_device *pdev)
 err3:
        platform_device_put(musb);
 
-err2:
-       musb_put_id(&pdev->dev, musbid);
-
 err1:
        kfree(glue);
 
@@ -1232,7 +1219,6 @@ static int __devexit tusb_remove(struct platform_device *pdev)
 {
        struct tusb6010_glue            *glue = platform_get_drvdata(pdev);
 
-       musb_put_id(&pdev->dev, glue->musb->id);
        platform_device_unregister(glue->musb);
        kfree(glue);
 
index 4197f307ae0fd5b241871fcd6143d4b966942adc..5e9053eb4298332a789b06c4ab58f81ffe165b72 100644 (file)
@@ -65,7 +65,6 @@ static int __devinit ux500_probe(struct platform_device *pdev)
        struct platform_device          *musb;
        struct ux500_glue               *glue;
        struct clk                      *clk;
-
        int                             ret = -ENOMEM;
 
        glue = kzalloc(sizeof(*glue), GFP_KERNEL);
@@ -74,18 +73,10 @@ static int __devinit ux500_probe(struct platform_device *pdev)
                goto err0;
        }
 
-       /* get the musb id */
-       musbid = musb_get_id(&pdev->dev, GFP_KERNEL);
-       if (musbid < 0) {
-               dev_err(&pdev->dev, "failed to allocate musb id\n");
-               ret = -ENOMEM;
-               goto err1;
-       }
-
-       musb = platform_device_alloc("musb-hdrc", musbid);
+       musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
        if (!musb) {
                dev_err(&pdev->dev, "failed to allocate musb device\n");
-               goto err2;
+               goto err1;
        }
 
        clk = clk_get(&pdev->dev, "usb");
@@ -101,7 +92,6 @@ static int __devinit ux500_probe(struct platform_device *pdev)
                goto err4;
        }
 
-       musb->id                        = musbid;
        musb->dev.parent                = &pdev->dev;
        musb->dev.dma_mask              = pdev->dev.dma_mask;
        musb->dev.coherent_dma_mask     = pdev->dev.coherent_dma_mask;
@@ -144,9 +134,6 @@ err4:
 err3:
        platform_device_put(musb);
 
-err2:
-       musb_put_id(&pdev->dev, musbid);
-
 err1:
        kfree(glue);
 
@@ -158,7 +145,6 @@ static int __devexit ux500_remove(struct platform_device *pdev)
 {
        struct ux500_glue       *glue = platform_get_drvdata(pdev);
 
-       musb_put_id(&pdev->dev, glue->musb->id);
        platform_device_unregister(glue->musb);
        clk_disable(glue->clk);
        clk_put(glue->clk);