mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-20 18:54:09 +08:00
usb: otg: mv_otg: use devm_xxx for probe
use devm_xxx for otg driver probe. So we do need care about the resources release in driver remove or failure handling in driver probe. Signed-off-by: Chao Xie <chao.xie@marvell.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
This commit is contained in:
parent
6a6f05f097
commit
fb3dfe13d0
@ -662,18 +662,9 @@ static struct attribute_group inputs_attr_group = {
|
|||||||
int mv_otg_remove(struct platform_device *pdev)
|
int mv_otg_remove(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct mv_otg *mvotg = platform_get_drvdata(pdev);
|
struct mv_otg *mvotg = platform_get_drvdata(pdev);
|
||||||
int clk_i;
|
|
||||||
|
|
||||||
sysfs_remove_group(&mvotg->pdev->dev.kobj, &inputs_attr_group);
|
sysfs_remove_group(&mvotg->pdev->dev.kobj, &inputs_attr_group);
|
||||||
|
|
||||||
if (mvotg->irq)
|
|
||||||
free_irq(mvotg->irq, mvotg);
|
|
||||||
|
|
||||||
if (mvotg->pdata->vbus)
|
|
||||||
free_irq(mvotg->pdata->vbus->irq, mvotg);
|
|
||||||
if (mvotg->pdata->id)
|
|
||||||
free_irq(mvotg->pdata->id->irq, mvotg);
|
|
||||||
|
|
||||||
if (mvotg->qwork) {
|
if (mvotg->qwork) {
|
||||||
flush_workqueue(mvotg->qwork);
|
flush_workqueue(mvotg->qwork);
|
||||||
destroy_workqueue(mvotg->qwork);
|
destroy_workqueue(mvotg->qwork);
|
||||||
@ -681,21 +672,9 @@ int mv_otg_remove(struct platform_device *pdev)
|
|||||||
|
|
||||||
mv_otg_disable(mvotg);
|
mv_otg_disable(mvotg);
|
||||||
|
|
||||||
if (mvotg->cap_regs)
|
|
||||||
iounmap(mvotg->cap_regs);
|
|
||||||
|
|
||||||
if (mvotg->phy_regs)
|
|
||||||
iounmap(mvotg->phy_regs);
|
|
||||||
|
|
||||||
for (clk_i = 0; clk_i <= mvotg->clknum; clk_i++)
|
|
||||||
clk_put(mvotg->clk[clk_i]);
|
|
||||||
|
|
||||||
usb_remove_phy(&mvotg->phy);
|
usb_remove_phy(&mvotg->phy);
|
||||||
platform_set_drvdata(pdev, NULL);
|
platform_set_drvdata(pdev, NULL);
|
||||||
|
|
||||||
kfree(mvotg->phy.otg);
|
|
||||||
kfree(mvotg);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -714,17 +693,15 @@ static int mv_otg_probe(struct platform_device *pdev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
size = sizeof(*mvotg) + sizeof(struct clk *) * pdata->clknum;
|
size = sizeof(*mvotg) + sizeof(struct clk *) * pdata->clknum;
|
||||||
mvotg = kzalloc(size, GFP_KERNEL);
|
mvotg = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
|
||||||
if (!mvotg) {
|
if (!mvotg) {
|
||||||
dev_err(&pdev->dev, "failed to allocate memory!\n");
|
dev_err(&pdev->dev, "failed to allocate memory!\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
otg = kzalloc(sizeof *otg, GFP_KERNEL);
|
otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL);
|
||||||
if (!otg) {
|
if (!otg)
|
||||||
kfree(mvotg);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
|
||||||
|
|
||||||
platform_set_drvdata(pdev, mvotg);
|
platform_set_drvdata(pdev, mvotg);
|
||||||
|
|
||||||
@ -733,18 +710,18 @@ static int mv_otg_probe(struct platform_device *pdev)
|
|||||||
|
|
||||||
mvotg->clknum = pdata->clknum;
|
mvotg->clknum = pdata->clknum;
|
||||||
for (clk_i = 0; clk_i < mvotg->clknum; clk_i++) {
|
for (clk_i = 0; clk_i < mvotg->clknum; clk_i++) {
|
||||||
mvotg->clk[clk_i] = clk_get(&pdev->dev, pdata->clkname[clk_i]);
|
mvotg->clk[clk_i] = devm_clk_get(&pdev->dev,
|
||||||
|
pdata->clkname[clk_i]);
|
||||||
if (IS_ERR(mvotg->clk[clk_i])) {
|
if (IS_ERR(mvotg->clk[clk_i])) {
|
||||||
retval = PTR_ERR(mvotg->clk[clk_i]);
|
retval = PTR_ERR(mvotg->clk[clk_i]);
|
||||||
goto err_put_clk;
|
return retval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mvotg->qwork = create_singlethread_workqueue("mv_otg_queue");
|
mvotg->qwork = create_singlethread_workqueue("mv_otg_queue");
|
||||||
if (!mvotg->qwork) {
|
if (!mvotg->qwork) {
|
||||||
dev_dbg(&pdev->dev, "cannot create workqueue for OTG\n");
|
dev_dbg(&pdev->dev, "cannot create workqueue for OTG\n");
|
||||||
retval = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto err_put_clk;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
INIT_DELAYED_WORK(&mvotg->work, mv_otg_work);
|
INIT_DELAYED_WORK(&mvotg->work, mv_otg_work);
|
||||||
@ -772,7 +749,7 @@ static int mv_otg_probe(struct platform_device *pdev)
|
|||||||
goto err_destroy_workqueue;
|
goto err_destroy_workqueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
mvotg->phy_regs = ioremap(r->start, resource_size(r));
|
mvotg->phy_regs = devm_ioremap(&pdev->dev, r->start, resource_size(r));
|
||||||
if (mvotg->phy_regs == NULL) {
|
if (mvotg->phy_regs == NULL) {
|
||||||
dev_err(&pdev->dev, "failed to map phy I/O memory\n");
|
dev_err(&pdev->dev, "failed to map phy I/O memory\n");
|
||||||
retval = -EFAULT;
|
retval = -EFAULT;
|
||||||
@ -784,21 +761,21 @@ static int mv_otg_probe(struct platform_device *pdev)
|
|||||||
if (r == NULL) {
|
if (r == NULL) {
|
||||||
dev_err(&pdev->dev, "no I/O memory resource defined\n");
|
dev_err(&pdev->dev, "no I/O memory resource defined\n");
|
||||||
retval = -ENODEV;
|
retval = -ENODEV;
|
||||||
goto err_unmap_phyreg;
|
goto err_destroy_workqueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
mvotg->cap_regs = ioremap(r->start, resource_size(r));
|
mvotg->cap_regs = devm_ioremap(&pdev->dev, r->start, resource_size(r));
|
||||||
if (mvotg->cap_regs == NULL) {
|
if (mvotg->cap_regs == NULL) {
|
||||||
dev_err(&pdev->dev, "failed to map I/O memory\n");
|
dev_err(&pdev->dev, "failed to map I/O memory\n");
|
||||||
retval = -EFAULT;
|
retval = -EFAULT;
|
||||||
goto err_unmap_phyreg;
|
goto err_destroy_workqueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we will acces controller register, so enable the udc controller */
|
/* we will acces controller register, so enable the udc controller */
|
||||||
retval = mv_otg_enable_internal(mvotg);
|
retval = mv_otg_enable_internal(mvotg);
|
||||||
if (retval) {
|
if (retval) {
|
||||||
dev_err(&pdev->dev, "mv otg enable error %d\n", retval);
|
dev_err(&pdev->dev, "mv otg enable error %d\n", retval);
|
||||||
goto err_unmap_capreg;
|
goto err_destroy_workqueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
mvotg->op_regs =
|
mvotg->op_regs =
|
||||||
@ -806,9 +783,9 @@ static int mv_otg_probe(struct platform_device *pdev)
|
|||||||
+ (readl(mvotg->cap_regs) & CAPLENGTH_MASK));
|
+ (readl(mvotg->cap_regs) & CAPLENGTH_MASK));
|
||||||
|
|
||||||
if (pdata->id) {
|
if (pdata->id) {
|
||||||
retval = request_threaded_irq(pdata->id->irq, NULL,
|
retval = devm_request_threaded_irq(&pdev->dev, pdata->id->irq,
|
||||||
mv_otg_inputs_irq,
|
NULL, mv_otg_inputs_irq,
|
||||||
IRQF_ONESHOT, "id", mvotg);
|
IRQF_ONESHOT, "id", mvotg);
|
||||||
if (retval) {
|
if (retval) {
|
||||||
dev_info(&pdev->dev,
|
dev_info(&pdev->dev,
|
||||||
"Failed to request irq for ID\n");
|
"Failed to request irq for ID\n");
|
||||||
@ -818,9 +795,9 @@ static int mv_otg_probe(struct platform_device *pdev)
|
|||||||
|
|
||||||
if (pdata->vbus) {
|
if (pdata->vbus) {
|
||||||
mvotg->clock_gating = 1;
|
mvotg->clock_gating = 1;
|
||||||
retval = request_threaded_irq(pdata->vbus->irq, NULL,
|
retval = devm_request_threaded_irq(&pdev->dev, pdata->vbus->irq,
|
||||||
mv_otg_inputs_irq,
|
NULL, mv_otg_inputs_irq,
|
||||||
IRQF_ONESHOT, "vbus", mvotg);
|
IRQF_ONESHOT, "vbus", mvotg);
|
||||||
if (retval) {
|
if (retval) {
|
||||||
dev_info(&pdev->dev,
|
dev_info(&pdev->dev,
|
||||||
"Failed to request irq for VBUS, "
|
"Failed to request irq for VBUS, "
|
||||||
@ -844,7 +821,7 @@ static int mv_otg_probe(struct platform_device *pdev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
mvotg->irq = r->start;
|
mvotg->irq = r->start;
|
||||||
if (request_irq(mvotg->irq, mv_otg_irq, IRQF_SHARED,
|
if (devm_request_irq(&pdev->dev, mvotg->irq, mv_otg_irq, IRQF_SHARED,
|
||||||
driver_name, mvotg)) {
|
driver_name, mvotg)) {
|
||||||
dev_err(&pdev->dev, "Request irq %d for OTG failed\n",
|
dev_err(&pdev->dev, "Request irq %d for OTG failed\n",
|
||||||
mvotg->irq);
|
mvotg->irq);
|
||||||
@ -857,14 +834,14 @@ static int mv_otg_probe(struct platform_device *pdev)
|
|||||||
if (retval < 0) {
|
if (retval < 0) {
|
||||||
dev_err(&pdev->dev, "can't register transceiver, %d\n",
|
dev_err(&pdev->dev, "can't register transceiver, %d\n",
|
||||||
retval);
|
retval);
|
||||||
goto err_free_irq;
|
goto err_disable_clk;
|
||||||
}
|
}
|
||||||
|
|
||||||
retval = sysfs_create_group(&pdev->dev.kobj, &inputs_attr_group);
|
retval = sysfs_create_group(&pdev->dev.kobj, &inputs_attr_group);
|
||||||
if (retval < 0) {
|
if (retval < 0) {
|
||||||
dev_dbg(&pdev->dev,
|
dev_dbg(&pdev->dev,
|
||||||
"Can't register sysfs attr group: %d\n", retval);
|
"Can't register sysfs attr group: %d\n", retval);
|
||||||
goto err_set_transceiver;
|
goto err_remove_phy;
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_lock_init(&mvotg->wq_lock);
|
spin_lock_init(&mvotg->wq_lock);
|
||||||
@ -879,30 +856,15 @@ static int mv_otg_probe(struct platform_device *pdev)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_set_transceiver:
|
err_remove_phy:
|
||||||
usb_remove_phy(&mvotg->phy);
|
usb_remove_phy(&mvotg->phy);
|
||||||
err_free_irq:
|
|
||||||
free_irq(mvotg->irq, mvotg);
|
|
||||||
err_disable_clk:
|
err_disable_clk:
|
||||||
if (pdata->vbus)
|
|
||||||
free_irq(pdata->vbus->irq, mvotg);
|
|
||||||
if (pdata->id)
|
|
||||||
free_irq(pdata->id->irq, mvotg);
|
|
||||||
mv_otg_disable_internal(mvotg);
|
mv_otg_disable_internal(mvotg);
|
||||||
err_unmap_capreg:
|
|
||||||
iounmap(mvotg->cap_regs);
|
|
||||||
err_unmap_phyreg:
|
|
||||||
iounmap(mvotg->phy_regs);
|
|
||||||
err_destroy_workqueue:
|
err_destroy_workqueue:
|
||||||
flush_workqueue(mvotg->qwork);
|
flush_workqueue(mvotg->qwork);
|
||||||
destroy_workqueue(mvotg->qwork);
|
destroy_workqueue(mvotg->qwork);
|
||||||
err_put_clk:
|
|
||||||
for (clk_i--; clk_i >= 0; clk_i--)
|
|
||||||
clk_put(mvotg->clk[clk_i]);
|
|
||||||
|
|
||||||
platform_set_drvdata(pdev, NULL);
|
platform_set_drvdata(pdev, NULL);
|
||||||
kfree(otg);
|
|
||||||
kfree(mvotg);
|
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user