usb: musb: convert to devm_* to allocate resources
PATCH 1/2 usb: musb: convert to devm_* to allocate resources
No functional change. Used devm_kzalloc and devm_clk_get instead of kzalloc and clk_get.
Signed-off-by Kishon Vijay Abraham I <[email protected]>
---
only *compile* tested.
drivers/usb/musb/am35x.c | 40 ++++++++++++++-------------------------- drivers/usb/musb/blackfin.c | 8 ++------ drivers/usb/musb/da8xx.c | 28 ++++++++++------------------ drivers/usb/musb/davinci.c | 28 ++++++++++------------------ drivers/usb/musb/musb_dsps.c | 4 +--- drivers/usb/musb/tusb6010.c | 16 ++++++---------- drivers/usb/musb/ux500.c | 28 ++++++++++------------------ 7 files changed, 53 insertions(+), 99 deletions(-)
drivers/usb/musb/am35x.c +14 -26
@@ -465,7 +465,7 @@ static int am35x_probe(struct platform_device *pdev)int ret = -ENOMEM ; - glue =kzalloc (sizeof (*glue),GFP_KERNEL ); + glue =devm_kzalloc (&pdev->dev,sizeof (*glue),GFP_KERNEL );if (!glue) {dev_err (&pdev->dev,"failed to allocate glue context\n" ); goto err0;
@@ -474,33 +474,33 @@ static int am35x_probe(struct platform_device *pdev) 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; } - phy_clk =clk_get (&pdev->dev,"fck" ); + phy_clk =devm_clk_get (&pdev->dev,"fck" );if (IS_ERR (phy_clk)) {dev_err (&pdev->dev,"failed to get PHY clock\n" ); ret =PTR_ERR (phy_clk); - goto err3; + goto err1; } - clk =clk_get (&pdev->dev,"ick" ); + clk =devm_clk_get (&pdev->dev,"ick" );if (IS_ERR (clk)) {dev_err (&pdev->dev,"failed to get clock\n" ); ret =PTR_ERR (clk); - goto err4; + goto err1; } ret =clk_enable (phy_clk);if (ret) {dev_err (&pdev->dev,"failed to enable PHY clock\n" ); - goto err5; + goto err1; } ret =clk_enable (clk);if (ret) {dev_err (&pdev->dev,"failed to enable clock\n" ); - goto err6; + goto err2; } musb->dev.parent = &pdev->dev;
@@ -520,40 +520,31 @@ static int am35x_probe(struct platform_device *pdev) pdev->num_resources);if (ret) {dev_err (&pdev->dev,"failed to add resources\n" ); - goto err7; + goto err3; } ret =platform_device_add_data (musb, pdata,sizeof (*pdata));if (ret) {dev_err (&pdev->dev,"failed to add platform_data\n" ); - goto err7; + goto err3; } ret =platform_device_add (musb);if (ret) {dev_err (&pdev->dev,"failed to register musb device\n" ); - goto err7; + goto err3; }return 0 ; -err7: +err3:clk_disable (clk); -err6: +err2:clk_disable (phy_clk); -err5: -clk_put (clk); - -err4: -clk_put (phy_clk); - -err3: -platform_device_put (musb); - err1: -kfree (glue); +platform_device_put (musb); err0:return ret;
@@ -566,9 +557,6 @@ static int am35x_remove(struct platform_device *pdev)platform_device_unregister (glue->musb);clk_disable (glue->clk);clk_disable (glue->phy_clk); -clk_put (glue->clk); -clk_put (glue->phy_clk); -kfree (glue);return 0 ; }
drivers/usb/musb/blackfin.c +2 -6
@@ -457,7 +457,7 @@ static int bfin_probe(struct platform_device *pdev)int ret = -ENOMEM ; - glue =kzalloc (sizeof (*glue),GFP_KERNEL ); + glue =devm_kzalloc (&pdev->dev,sizeof (*glue),GFP_KERNEL );if (!glue) {dev_err (&pdev->dev,"failed to allocate glue context\n" ); goto err0;
@@ -466,7 +466,7 @@ static int bfin_probe(struct platform_device *pdev) 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->dev.parent = &pdev->dev;
@@ -517,9 +517,6 @@ static int bfin_probe(struct platform_device *pdev) err3:platform_device_put (musb); -err1: -kfree (glue); - err0:return ret; }
@@ -529,7 +526,6 @@ static int bfin_remove(struct platform_device *pdev)struct bfin_glue *glue =platform_get_drvdata (pdev);platform_device_unregister (glue->musb); -kfree (glue);return 0 ; }
drivers/usb/musb/da8xx.c +10 -18
@@ -485,7 +485,7 @@ static int da8xx_probe(struct platform_device *pdev)int ret = -ENOMEM ; - glue =kzalloc (sizeof (*glue),GFP_KERNEL ); + glue =devm_kzalloc (&pdev->dev,sizeof (*glue),GFP_KERNEL );if (!glue) {dev_err (&pdev->dev,"failed to allocate glue context\n" ); goto err0;
@@ -494,20 +494,20 @@ static int da8xx_probe(struct platform_device *pdev) 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; } - clk =clk_get (&pdev->dev,"usb20" ); + clk =devm_clk_get (&pdev->dev,"usb20" );if (IS_ERR (clk)) {dev_err (&pdev->dev,"failed to get clock\n" ); ret =PTR_ERR (clk); - goto err3; + goto err1; } ret =clk_enable (clk);if (ret) {dev_err (&pdev->dev,"failed to enable clock\n" ); - goto err4; + goto err1; } musb->dev.parent = &pdev->dev;
@@ -539,34 +539,28 @@ static int da8xx_probe(struct platform_device *pdev) ARRAY_SIZE(musb_resources));if (ret) {dev_err (&pdev->dev,"failed to add resources\n" ); - goto err5; + goto err2; } ret =platform_device_add_data (musb, pdata,sizeof (*pdata));if (ret) {dev_err (&pdev->dev,"failed to add platform_data\n" ); - goto err5; + goto err2; } ret =platform_device_add (musb);if (ret) {dev_err (&pdev->dev,"failed to register musb device\n" ); - goto err5; + goto err2; }return 0 ; -err5: +err2:clk_disable (clk); -err4: -clk_put (clk); - -err3: -platform_device_put (musb); - err1: -kfree (glue); +platform_device_put (musb); err0:return ret;
@@ -578,8 +572,6 @@ static int da8xx_remove(struct platform_device *pdev)platform_device_unregister (glue->musb);clk_disable (glue->clk); -clk_put (glue->clk); -kfree (glue);return 0 ; }
drivers/usb/musb/davinci.c +10 -18
@@ -517,7 +517,7 @@ static int davinci_probe(struct platform_device *pdev)int ret = -ENOMEM ; - glue =kzalloc (sizeof (*glue),GFP_KERNEL ); + glue =devm_kzalloc (&pdev->dev,sizeof (*glue),GFP_KERNEL );if (!glue) {dev_err (&pdev->dev,"failed to allocate glue context\n" ); goto err0;
@@ -526,20 +526,20 @@ static int davinci_probe(struct platform_device *pdev) 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; } - clk =clk_get (&pdev->dev,"usb" ); + clk =devm_clk_get (&pdev->dev,"usb" );if (IS_ERR (clk)) {dev_err (&pdev->dev,"failed to get clock\n" ); ret =PTR_ERR (clk); - goto err3; + goto err1; } ret =clk_enable (clk);if (ret) {dev_err (&pdev->dev,"failed to enable clock\n" ); - goto err4; + goto err1; } musb->dev.parent = &pdev->dev;
@@ -571,34 +571,28 @@ static int davinci_probe(struct platform_device *pdev) ARRAY_SIZE(musb_resources));if (ret) {dev_err (&pdev->dev,"failed to add resources\n" ); - goto err5; + goto err2; } ret =platform_device_add_data (musb, pdata,sizeof (*pdata));if (ret) {dev_err (&pdev->dev,"failed to add platform_data\n" ); - goto err5; + goto err2; } ret =platform_device_add (musb);if (ret) {dev_err (&pdev->dev,"failed to register musb device\n" ); - goto err5; + goto err2; }return 0 ; -err5: +err2:clk_disable (clk); -err4: -clk_put (clk); - -err3: -platform_device_put (musb); - err1: -kfree (glue); +platform_device_put (musb); err0:return ret;
@@ -610,8 +604,6 @@ static int davinci_remove(struct platform_device *pdev)platform_device_unregister (glue->musb);clk_disable (glue->clk); -clk_put (glue->clk); -kfree (glue);return 0 ; }
drivers/usb/musb/musb_dsps.c +1 -3
@@ -524,7 +524,7 @@ static int dsps_probe(struct platform_device *pdev) wrp = match->data;/* allocate glue */ - glue =kzalloc (sizeof (*glue),GFP_KERNEL ); + glue =devm_kzalloc (&pdev->dev,sizeof (*glue),GFP_KERNEL );if (!glue) {dev_err (&pdev->dev,"unable to allocate glue memory\n" );return -ENOMEM ;
@@ -552,7 +552,6 @@ err3:pm_runtime_put (&pdev->dev); err2:pm_runtime_disable (&pdev->dev); -kfree (glue);return ret; }
@@ -565,7 +564,6 @@ static int dsps_remove(struct platform_device *pdev)/* disable usbss clocks */ pm_runtime_put (&pdev->dev);pm_runtime_disable (&pdev->dev); -kfree (glue);return 0 ; }
drivers/usb/musb/tusb6010.c +6 -10
@@ -1163,7 +1163,7 @@ static int tusb_probe(struct platform_device *pdev)int ret = -ENOMEM ; - glue =kzalloc (sizeof (*glue),GFP_KERNEL ); + glue =devm_kzalloc (&pdev->dev,sizeof (*glue),GFP_KERNEL );if (!glue) {dev_err (&pdev->dev,"failed to allocate glue context\n" ); goto err0;
@@ -1172,7 +1172,7 @@ static int tusb_probe(struct platform_device *pdev) 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->dev.parent = &pdev->dev;
@@ -1208,28 +1208,25 @@ static int tusb_probe(struct platform_device *pdev) ARRAY_SIZE(musb_resources));if (ret) {dev_err (&pdev->dev,"failed to add resources\n" ); - goto err3; + goto err1; } ret =platform_device_add_data (musb, pdata,sizeof (*pdata));if (ret) {dev_err (&pdev->dev,"failed to add platform_data\n" ); - goto err3; + goto err1; } ret =platform_device_add (musb);if (ret) {dev_err (&pdev->dev,"failed to register musb device\n" ); - goto err3; + goto err1; }return 0 ; -err3: -platform_device_put (musb); - err1: -kfree (glue); +platform_device_put (musb); err0:return ret;
@@ -1240,7 +1237,6 @@ static int tusb_remove(struct platform_device *pdev)struct tusb6010_glue *glue =platform_get_drvdata (pdev);platform_device_unregister (glue->musb); -kfree (glue);return 0 ; }
drivers/usb/musb/ux500.c +10 -18
@@ -247,7 +247,7 @@ static int ux500_probe(struct platform_device *pdev) } } - glue =kzalloc (sizeof (*glue),GFP_KERNEL ); + glue =devm_kzalloc (&pdev->dev,sizeof (*glue),GFP_KERNEL );if (!glue) {dev_err (&pdev->dev,"failed to allocate glue context\n" ); goto err0;
@@ -256,20 +256,20 @@ static int ux500_probe(struct platform_device *pdev) 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; } - clk =clk_get (&pdev->dev,"usb" ); + clk =devm_clk_get (&pdev->dev,"usb" );if (IS_ERR (clk)) {dev_err (&pdev->dev,"failed to get clock\n" ); ret =PTR_ERR (clk); - goto err3; + goto err1; } ret =clk_prepare_enable (clk);if (ret) {dev_err (&pdev->dev,"failed to enable clock\n" ); - goto err4; + goto err1; } musb->dev.parent = &pdev->dev;
@@ -303,34 +303,28 @@ static int ux500_probe(struct platform_device *pdev) ARRAY_SIZE(musb_resources));if (ret) {dev_err (&pdev->dev,"failed to add resources\n" ); - goto err5; + goto err2; } ret =platform_device_add_data (musb, pdata,sizeof (*pdata));if (ret) {dev_err (&pdev->dev,"failed to add platform_data\n" ); - goto err5; + goto err2; } ret =platform_device_add (musb);if (ret) {dev_err (&pdev->dev,"failed to register musb device\n" ); - goto err5; + goto err2; }return 0 ; -err5: +err2:clk_disable_unprepare (clk); -err4: -clk_put (clk); - -err3: -platform_device_put (musb); - err1: -kfree (glue); +platform_device_put (musb); err0:return ret;
@@ -342,8 +336,6 @@ static int ux500_remove(struct platform_device *pdev)platform_device_unregister (glue->musb);clk_disable_unprepare (glue->clk); -clk_put (glue->clk); -kfree (glue);return 0 ; }
Signature · 1 line
1.7.10.4
PATCH 2/2 usb: musb: pass on all the required resources from glue to musb core
musb glue have to pass either 2 resources or 3 resources to the musb core (musb core irq number, dma irq number and a memory
resource). So allocated *resource* for musb core in glue (based on the number of resources in glue), copy all the resources from glue to core before creating the musb core device. This prevents the need to know the number of resources beforehand.
Signed-off-by Kishon Vijay Abraham I <[email protected]>
---
Tested omap4 panda and omap3 beagle for enumeration . All other platforms compile tested only.
drivers/usb/musb/am35x.c | 16 +++++++++++++++- drivers/usb/musb/blackfin.c | 28 ++++++++++++++-------------- drivers/usb/musb/da8xx.c | 28 ++++++++++++++-------------- drivers/usb/musb/davinci.c | 28 ++++++++++++++-------------- drivers/usb/musb/omap2430.c | 33 ++++++++++++++------------------- drivers/usb/musb/tusb6010.c | 33 ++++++++++++++------------------- drivers/usb/musb/ux500.c | 28 ++++++++++++++-------------- 7 files changed, 99 insertions(+), 95 deletions(-)
drivers/usb/musb/am35x.c +15 -1
@@ -457,8 +457,10 @@ static u64 am35x_dmamask = DMA_BIT_MASK(32);static int am35x_probe (struct platform_device *pdev) {struct musb_hdrc_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct resource *musb_resources;struct platform_device *musb;struct am35x_glue *glue; +int i;struct clk *phy_clk;struct clk *clk;
@@ -477,6 +479,11 @@ static int am35x_probe(struct platform_device *pdev) goto err0; } + musb_resources =devm_kzalloc (&pdev->dev, pdev->num_resources * +sizeof (*musb_resources),GFP_KERNEL ); +if (!musb_resources) + goto err1; + phy_clk =devm_clk_get (&pdev->dev,"fck" );if (IS_ERR (phy_clk)) {dev_err (&pdev->dev,"failed to get PHY clock\n" );
@@ -516,7 +523,14 @@ static int am35x_probe(struct platform_device *pdev)platform_set_drvdata (pdev, glue); - ret =platform_device_add_resources (musb, pdev->resource, +for (i =0 ; i < pdev->num_resources; i++) { + musb_resources[i].name = pdev->resource[i].name; + musb_resources[i].start = pdev->resource[i].start; + musb_resources[i].end = pdev->resource[i].end; + musb_resources[i].flags = pdev->resource[i].flags; + } + + ret =platform_device_add_resources (musb, musb_resources, pdev->num_resources);if (ret) {dev_err (&pdev->dev,"failed to add resources\n" );
drivers/usb/musb/blackfin.c +14 -14
@@ -450,10 +450,11 @@ static u64 bfin_dmamask = DMA_BIT_MASK(32);static int bfin_probe (struct platform_device *pdev) { -struct resource musb_resources[2 ]; +struct resource *musb_resources;struct musb_hdrc_platform_data *pdata =dev_get_platdata (&pdev->dev);struct platform_device *musb;struct bfin_glue *glue; +int i;int ret = -ENOMEM ;
@@ -469,6 +470,11 @@ static int bfin_probe(struct platform_device *pdev) goto err0; } + musb_resources =devm_kzalloc (&pdev->dev, pdev->num_resources * +sizeof (*musb_resources),GFP_KERNEL ); +if (!musb_resources) + goto err3; + musb->dev.parent = &pdev->dev; musb->dev.dma_mask = &bfin_dmamask; musb->dev.coherent_dma_mask = bfin_dmamask;
@@ -480,21 +486,15 @@ static int bfin_probe(struct platform_device *pdev)platform_set_drvdata (pdev, glue); -memset (musb_resources,0x00 ,sizeof (*musb_resources) * -ARRAY_SIZE (musb_resources)); - - musb_resources[0 ].name = pdev->resource[0 ].name; - musb_resources[0 ].start = pdev->resource[0 ].start; - musb_resources[0 ].end = pdev->resource[0 ].end; - musb_resources[0 ].flags = pdev->resource[0 ].flags; - - musb_resources[1 ].name = pdev->resource[1 ].name; - musb_resources[1 ].start = pdev->resource[1 ].start; - musb_resources[1 ].end = pdev->resource[1 ].end; - musb_resources[1 ].flags = pdev->resource[1 ].flags; +for (i =0 ; i < pdev->num_resources; i++) { + musb_resources[i].name = pdev->resource[i].name; + musb_resources[i].start = pdev->resource[i].start; + musb_resources[i].end = pdev->resource[i].end; + musb_resources[i].flags = pdev->resource[i].flags; + } ret =platform_device_add_resources (musb, musb_resources, -ARRAY_SIZE (musb_resources)); + pdev->num_resources);if (ret) {dev_err (&pdev->dev,"failed to add resources\n" ); goto err3;
drivers/usb/musb/da8xx.c +14 -14
@@ -476,10 +476,11 @@ static u64 da8xx_dmamask = DMA_BIT_MASK(32);static int da8xx_probe (struct platform_device *pdev) { -struct resource musb_resources[2 ]; +struct resource *musb_resources;struct musb_hdrc_platform_data *pdata =dev_get_platdata (&pdev->dev);struct platform_device *musb;struct da8xx_glue *glue; +int i;struct clk *clk;
@@ -497,6 +498,11 @@ static int da8xx_probe(struct platform_device *pdev) goto err0; } + musb_resources =devm_kzalloc (&pdev->dev, pdev->num_resources * +sizeof (*musb_resources),GFP_KERNEL ); +if (!musb_resources) + goto err1; + clk =devm_clk_get (&pdev->dev,"usb20" );if (IS_ERR (clk)) {dev_err (&pdev->dev,"failed to get clock\n" );
@@ -522,21 +528,15 @@ static int da8xx_probe(struct platform_device *pdev)platform_set_drvdata (pdev, glue); -memset (musb_resources,0x00 ,sizeof (*musb_resources) * -ARRAY_SIZE (musb_resources)); - - musb_resources[0 ].name = pdev->resource[0 ].name; - musb_resources[0 ].start = pdev->resource[0 ].start; - musb_resources[0 ].end = pdev->resource[0 ].end; - musb_resources[0 ].flags = pdev->resource[0 ].flags; - - musb_resources[1 ].name = pdev->resource[1 ].name; - musb_resources[1 ].start = pdev->resource[1 ].start; - musb_resources[1 ].end = pdev->resource[1 ].end; - musb_resources[1 ].flags = pdev->resource[1 ].flags; +for (i =0 ; i < pdev->num_resources; i++) { + musb_resources[i].name = pdev->resource[i].name; + musb_resources[i].start = pdev->resource[i].start; + musb_resources[i].end = pdev->resource[i].end; + musb_resources[i].flags = pdev->resource[i].flags; + } ret =platform_device_add_resources (musb, musb_resources, -ARRAY_SIZE (musb_resources)); + pdev->num_resources);if (ret) {dev_err (&pdev->dev,"failed to add resources\n" ); goto err2;
drivers/usb/musb/davinci.c +14 -14
@@ -509,11 +509,12 @@ static u64 davinci_dmamask = DMA_BIT_MASK(32);static int davinci_probe (struct platform_device *pdev) { -struct resource musb_resources[2 ]; +struct resource *musb_resources;struct musb_hdrc_platform_data *pdata =dev_get_platdata (&pdev->dev);struct platform_device *musb;struct davinci_glue *glue;struct clk *clk; +int i;int ret = -ENOMEM ;
@@ -536,6 +537,11 @@ static int davinci_probe(struct platform_device *pdev) goto err1; } + musb_resources =devm_kzalloc (&pdev->dev, pdev->num_resources * +sizeof (*musb_resources),GFP_KERNEL ); +if (!musb_resources) + goto err1; + ret =clk_enable (clk);if (ret) {dev_err (&pdev->dev,"failed to enable clock\n" );
@@ -554,21 +560,15 @@ static int davinci_probe(struct platform_device *pdev)platform_set_drvdata (pdev, glue); -memset (musb_resources,0x00 ,sizeof (*musb_resources) * -ARRAY_SIZE (musb_resources)); - - musb_resources[0 ].name = pdev->resource[0 ].name; - musb_resources[0 ].start = pdev->resource[0 ].start; - musb_resources[0 ].end = pdev->resource[0 ].end; - musb_resources[0 ].flags = pdev->resource[0 ].flags; - - musb_resources[1 ].name = pdev->resource[1 ].name; - musb_resources[1 ].start = pdev->resource[1 ].start; - musb_resources[1 ].end = pdev->resource[1 ].end; - musb_resources[1 ].flags = pdev->resource[1 ].flags; +for (i =0 ; i < pdev->num_resources; i++) { + musb_resources[i].name = pdev->resource[i].name; + musb_resources[i].start = pdev->resource[i].start; + musb_resources[i].end = pdev->resource[i].end; + musb_resources[i].flags = pdev->resource[i].flags; + } ret =platform_device_add_resources (musb, musb_resources, -ARRAY_SIZE (musb_resources)); + pdev->num_resources);if (ret) {dev_err (&pdev->dev,"failed to add resources\n" ); goto err2;
drivers/usb/musb/omap2430.c +14 -19
@@ -481,7 +481,7 @@ static u64 omap2430_dmamask = DMA_BIT_MASK(32);static int omap2430_probe (struct platform_device *pdev) { -struct resource musb_resources[3 ]; +struct resource *musb_resources;struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data;struct omap_musb_board_data *data;struct platform_device *musb;
@@ -489,6 +489,7 @@ static int omap2430_probe(struct platform_device *pdev)struct device_node *np = pdev->dev.of_node;struct musb_hdrc_config *config;int ret = -ENOMEM ; +int i; glue =devm_kzalloc (&pdev->dev,sizeof (*glue),GFP_KERNEL );if (!glue) {
@@ -502,6 +503,11 @@ static int omap2430_probe(struct platform_device *pdev) goto err0; } + musb_resources =devm_kzalloc (&pdev->dev, pdev->num_resources * +sizeof (*musb_resources),GFP_KERNEL ); +if (!musb_resources) + goto err2; + musb->dev.parent = &pdev->dev; musb->dev.dma_mask = &omap2430_dmamask; musb->dev.coherent_dma_mask = omap2430_dmamask;
@@ -568,26 +574,15 @@ static int omap2430_probe(struct platform_device *pdev)INIT_WORK (&glue->omap_musb_mailbox_work, omap_musb_mailbox_work); -memset (musb_resources,0x00 ,sizeof (*musb_resources) * -ARRAY_SIZE (musb_resources)); - - musb_resources[0 ].name = pdev->resource[0 ].name; - musb_resources[0 ].start = pdev->resource[0 ].start; - musb_resources[0 ].end = pdev->resource[0 ].end; - musb_resources[0 ].flags = pdev->resource[0 ].flags; - - musb_resources[1 ].name = pdev->resource[1 ].name; - musb_resources[1 ].start = pdev->resource[1 ].start; - musb_resources[1 ].end = pdev->resource[1 ].end; - musb_resources[1 ].flags = pdev->resource[1 ].flags; - - musb_resources[2 ].name = pdev->resource[2 ].name; - musb_resources[2 ].start = pdev->resource[2 ].start; - musb_resources[2 ].end = pdev->resource[2 ].end; - musb_resources[2 ].flags = pdev->resource[2 ].flags; +for (i =0 ; i < pdev->num_resources; i++) { + musb_resources[i].name = pdev->resource[i].name; + musb_resources[i].start = pdev->resource[i].start; + musb_resources[i].end = pdev->resource[i].end; + musb_resources[i].flags = pdev->resource[i].flags; + } ret =platform_device_add_resources (musb, musb_resources, -ARRAY_SIZE (musb_resources)); + pdev->num_resources);if (ret) {dev_err (&pdev->dev,"failed to add resources\n" ); goto err2;
drivers/usb/musb/tusb6010.c +14 -19
@@ -1156,10 +1156,11 @@ static u64 tusb_dmamask = DMA_BIT_MASK(32);static int tusb_probe (struct platform_device *pdev) { -struct resource musb_resources[3 ]; +struct resource *musb_resources;struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data;struct platform_device *musb;struct tusb6010_glue *glue; +int i;int ret = -ENOMEM ;
@@ -1175,6 +1176,11 @@ static int tusb_probe(struct platform_device *pdev) goto err0; } + musb_resources =devm_kzalloc (&pdev->dev, pdev->num_resources * +sizeof (*musb_resources),GFP_KERNEL ); +if (!musb_resources) + goto err1; + musb->dev.parent = &pdev->dev; musb->dev.dma_mask = &tusb_dmamask; musb->dev.coherent_dma_mask = tusb_dmamask;
@@ -1186,26 +1192,15 @@ static int tusb_probe(struct platform_device *pdev)platform_set_drvdata (pdev, glue); -memset (musb_resources,0x00 ,sizeof (*musb_resources) * -ARRAY_SIZE (musb_resources)); - - musb_resources[0 ].name = pdev->resource[0 ].name; - musb_resources[0 ].start = pdev->resource[0 ].start; - musb_resources[0 ].end = pdev->resource[0 ].end; - musb_resources[0 ].flags = pdev->resource[0 ].flags; - - musb_resources[1 ].name = pdev->resource[1 ].name; - musb_resources[1 ].start = pdev->resource[1 ].start; - musb_resources[1 ].end = pdev->resource[1 ].end; - musb_resources[1 ].flags = pdev->resource[1 ].flags; - - musb_resources[2 ].name = pdev->resource[2 ].name; - musb_resources[2 ].start = pdev->resource[2 ].start; - musb_resources[2 ].end = pdev->resource[2 ].end; - musb_resources[2 ].flags = pdev->resource[2 ].flags; +for (i =0 ; i < pdev->num_resources; i++) { + musb_resources[i].name = pdev->resource[i].name; + musb_resources[i].start = pdev->resource[i].start; + musb_resources[i].end = pdev->resource[i].end; + musb_resources[i].flags = pdev->resource[i].flags; + } ret =platform_device_add_resources (musb, musb_resources, -ARRAY_SIZE (musb_resources)); + pdev->num_resources);if (ret) {dev_err (&pdev->dev,"failed to add resources\n" ); goto err1;
drivers/usb/musb/ux500.c +14 -14
@@ -226,12 +226,13 @@ ux500_of_probe(struct platform_device *pdev, struct device_node *np)static int ux500_probe (struct platform_device *pdev) { -struct resource musb_resources[2 ]; +struct resource *musb_resources;struct musb_hdrc_platform_data *pdata =dev_get_platdata (&pdev->dev);struct device_node *np = pdev->dev.of_node;struct platform_device *musb;struct ux500_glue *glue;struct clk *clk; +int i;int ret = -ENOMEM ;if (!pdata) {
@@ -259,6 +260,11 @@ static int ux500_probe(struct platform_device *pdev) goto err0; } + musb_resources =devm_kzalloc (&pdev->dev, pdev->num_resources * +sizeof (*musb_resources),GFP_KERNEL ); +if (!musb_resources) + goto err1; + clk =devm_clk_get (&pdev->dev,"usb" );if (IS_ERR (clk)) {dev_err (&pdev->dev,"failed to get clock\n" );
@@ -286,21 +292,15 @@ static int ux500_probe(struct platform_device *pdev)platform_set_drvdata (pdev, glue); -memset (musb_resources,0x00 ,sizeof (*musb_resources) * -ARRAY_SIZE (musb_resources)); - - musb_resources[0 ].name = pdev->resource[0 ].name; - musb_resources[0 ].start = pdev->resource[0 ].start; - musb_resources[0 ].end = pdev->resource[0 ].end; - musb_resources[0 ].flags = pdev->resource[0 ].flags; - - musb_resources[1 ].name = pdev->resource[1 ].name; - musb_resources[1 ].start = pdev->resource[1 ].start; - musb_resources[1 ].end = pdev->resource[1 ].end; - musb_resources[1 ].flags = pdev->resource[1 ].flags; +for (i =0 ; i < pdev->num_resources; i++) { + musb_resources[i].name = pdev->resource[i].name; + musb_resources[i].start = pdev->resource[i].start; + musb_resources[i].end = pdev->resource[i].end; + musb_resources[i].flags = pdev->resource[i].flags; + } ret =platform_device_add_resources (musb, musb_resources, -ARRAY_SIZE (musb_resources)); + pdev->num_resources);if (ret) {dev_err (&pdev->dev,"failed to add resources\n" ); goto err2;
Signature · 1 line
1.7.10.4