Skip to content

Commit

Permalink
usb: s3c-hsotg: Use devm_* functions in s3c-hsotg.c file
Browse files Browse the repository at this point in the history
devm_* functions are used to replace kzalloc, request_mem_region, ioremap
and request_irq functions in probe call. With the usage of devm_* functions
explicit freeing and unmapping is not required.

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
  • Loading branch information
Sachin Kamat authored and Felipe Balbi committed Jun 4, 2012
1 parent dd8e938 commit 338edab
Showing 1 changed file with 11 additions and 40 deletions.
51 changes: 11 additions & 40 deletions drivers/usb/gadget/s3c-hsotg.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ struct s3c_hsotg_ep {
* @driver: USB gadget driver
* @plat: The platform specific configuration data.
* @regs: The memory area mapped for accessing registers.
* @regs_res: The resource that was allocated when claiming register space.
* @irq: The IRQ number we are using
* @supplies: Definition of USB power supplies
* @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos.
Expand All @@ -158,7 +157,6 @@ struct s3c_hsotg {
struct s3c_hsotg_plat *plat;

void __iomem *regs;
struct resource *regs_res;
int irq;
struct clk *clk;

Expand Down Expand Up @@ -3477,7 +3475,7 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev)
return -EINVAL;
}

hsotg = kzalloc(sizeof(struct s3c_hsotg), GFP_KERNEL);
hsotg = devm_kzalloc(&pdev->dev, sizeof(struct s3c_hsotg), GFP_KERNEL);
if (!hsotg) {
dev_err(dev, "cannot get memory\n");
return -ENOMEM;
Expand All @@ -3489,46 +3487,33 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev)
hsotg->clk = clk_get(&pdev->dev, "otg");
if (IS_ERR(hsotg->clk)) {
dev_err(dev, "cannot get otg clock\n");
ret = PTR_ERR(hsotg->clk);
goto err_mem;
return PTR_ERR(hsotg->clk);
}

platform_set_drvdata(pdev, hsotg);

res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
dev_err(dev, "cannot find register resource 0\n");
ret = -EINVAL;
goto err_clk;
}

hsotg->regs_res = request_mem_region(res->start, resource_size(res),
dev_name(dev));
if (!hsotg->regs_res) {
dev_err(dev, "cannot reserve registers\n");
ret = -ENOENT;
goto err_clk;
}

hsotg->regs = ioremap(res->start, resource_size(res));
hsotg->regs = devm_request_and_ioremap(&pdev->dev, res);
if (!hsotg->regs) {
dev_err(dev, "cannot map registers\n");
ret = -ENXIO;
goto err_regs_res;
goto err_clk;
}

ret = platform_get_irq(pdev, 0);
if (ret < 0) {
dev_err(dev, "cannot find IRQ\n");
goto err_regs;
goto err_clk;
}

hsotg->irq = ret;

ret = request_irq(ret, s3c_hsotg_irq, 0, dev_name(dev), hsotg);
ret = devm_request_irq(&pdev->dev, hsotg->irq, s3c_hsotg_irq, 0,
dev_name(dev), hsotg);
if (ret < 0) {
dev_err(dev, "cannot claim IRQ\n");
goto err_regs;
goto err_clk;
}

dev_info(dev, "regs %p, irq %d\n", hsotg->regs, hsotg->irq);
Expand Down Expand Up @@ -3558,7 +3543,7 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev)
hsotg->supplies);
if (ret) {
dev_err(dev, "failed to request supplies: %d\n", ret);
goto err_irq;
goto err_clk;
}

ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies),
Expand Down Expand Up @@ -3642,19 +3627,11 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev)
err_supplies:
s3c_hsotg_phy_disable(hsotg);
regulator_bulk_free(ARRAY_SIZE(hsotg->supplies), hsotg->supplies);
err_irq:
free_irq(hsotg->irq, hsotg);
err_regs:
iounmap(hsotg->regs);

err_regs_res:
release_resource(hsotg->regs_res);
kfree(hsotg->regs_res);

err_clk:
clk_disable_unprepare(hsotg->clk);
clk_put(hsotg->clk);
err_mem:
kfree(hsotg);

return ret;
}

Expand All @@ -3675,12 +3652,6 @@ static int __devexit s3c_hsotg_remove(struct platform_device *pdev)
usb_gadget_unregister_driver(hsotg->driver);
}

free_irq(hsotg->irq, hsotg);
iounmap(hsotg->regs);

release_resource(hsotg->regs_res);
kfree(hsotg->regs_res);

s3c_hsotg_phy_disable(hsotg);
regulator_bulk_free(ARRAY_SIZE(hsotg->supplies), hsotg->supplies);

Expand Down

0 comments on commit 338edab

Please sign in to comment.