dect
/
linux-2.6
Archived
13
0
Fork 0

usb: musb: remove hand-crafted id handling

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>
This commit is contained in:
Sebastian Andrzej Siewior 2012-10-31 16:12:43 +01:00 committed by Felipe Balbi
parent b18d26f6ad
commit 2f77116425
10 changed files with 25 additions and 171 deletions

View 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);

View 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;
musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
if (!musb) {
dev_err(&pdev->dev, "failed to allocate musb device\n");
goto err1;
}
musb = platform_device_alloc("musb-hdrc", musbid);
if (!musb) {
dev_err(&pdev->dev, "failed to allocate musb device\n");
goto err2;
}
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);

View 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);

View 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);

View File

@ -116,7 +116,6 @@
#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)
{

View 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);

View 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);

View 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;
musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
if (!musb) {
dev_err(&pdev->dev, "failed to allocate musb device\n");
goto err0;
}
musb = platform_device_alloc("musb-hdrc", musbid);
if (!musb) {
dev_err(&pdev->dev, "failed to allocate musb device\n");
goto err1;
}
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;

View 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;
musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
if (!musb) {
dev_err(&pdev->dev, "failed to allocate musb device\n");
goto err1;
}
musb = platform_device_alloc("musb-hdrc", musbid);
if (!musb) {
dev_err(&pdev->dev, "failed to allocate musb device\n");
goto err2;
}
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);

View 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);