Skip to content

Commit 814f047

Browse files
Bence Csókásvinodkoul
authored andcommitted
dmaengine: sun4i: Simplify error handling in probe()
Clean up error handling by using devm functions and dev_err_probe(). This should make it easier to add new code, as we can eliminate the "goto ladder" in sun4i_dma_probe(). Suggested-by: Chen-Yu Tsai <[email protected]> Reviewed-by: Jernej Skrabec <[email protected]> Acked-by: Chen-Yu Tsai <[email protected]> Reviewed-by: Julian Calaby <[email protected]> Signed-off-by: Bence Csókás <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent e54dd50 commit 814f047

File tree

1 file changed

+13
-33
lines changed

1 file changed

+13
-33
lines changed

drivers/dma/sun4i-dma.c

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,11 +1249,10 @@ static int sun4i_dma_probe(struct platform_device *pdev)
12491249
if (priv->irq < 0)
12501250
return priv->irq;
12511251

1252-
priv->clk = devm_clk_get(&pdev->dev, NULL);
1253-
if (IS_ERR(priv->clk)) {
1254-
dev_err(&pdev->dev, "No clock specified\n");
1255-
return PTR_ERR(priv->clk);
1256-
}
1252+
priv->clk = devm_clk_get_enabled(&pdev->dev, NULL);
1253+
if (IS_ERR(priv->clk))
1254+
return dev_err_probe(&pdev->dev, PTR_ERR(priv->clk),
1255+
"Couldn't start the clock\n");
12571256

12581257
if (priv->cfg->has_reset) {
12591258
priv->rst = devm_reset_control_get_exclusive_deasserted(&pdev->dev, NULL);
@@ -1328,12 +1327,6 @@ static int sun4i_dma_probe(struct platform_device *pdev)
13281327
vchan_init(&vchan->vc, &priv->slave);
13291328
}
13301329

1331-
ret = clk_prepare_enable(priv->clk);
1332-
if (ret) {
1333-
dev_err(&pdev->dev, "Couldn't enable the clock\n");
1334-
return ret;
1335-
}
1336-
13371330
/*
13381331
* Make sure the IRQs are all disabled and accounted for. The bootloader
13391332
* likes to leave these dirty
@@ -1343,33 +1336,23 @@ static int sun4i_dma_probe(struct platform_device *pdev)
13431336

13441337
ret = devm_request_irq(&pdev->dev, priv->irq, sun4i_dma_interrupt,
13451338
0, dev_name(&pdev->dev), priv);
1346-
if (ret) {
1347-
dev_err(&pdev->dev, "Cannot request IRQ\n");
1348-
goto err_clk_disable;
1349-
}
1339+
if (ret)
1340+
return dev_err_probe(&pdev->dev, ret, "Cannot request IRQ\n");
13501341

1351-
ret = dma_async_device_register(&priv->slave);
1352-
if (ret) {
1353-
dev_warn(&pdev->dev, "Failed to register DMA engine device\n");
1354-
goto err_clk_disable;
1355-
}
1342+
ret = dmaenginem_async_device_register(&priv->slave);
1343+
if (ret)
1344+
return dev_err_probe(&pdev->dev, ret,
1345+
"Failed to register DMA engine device\n");
13561346

13571347
ret = of_dma_controller_register(pdev->dev.of_node, sun4i_dma_of_xlate,
13581348
priv);
1359-
if (ret) {
1360-
dev_err(&pdev->dev, "of_dma_controller_register failed\n");
1361-
goto err_dma_unregister;
1362-
}
1349+
if (ret)
1350+
return dev_err_probe(&pdev->dev, ret,
1351+
"Failed to register translation function\n");
13631352

13641353
dev_dbg(&pdev->dev, "Successfully probed SUN4I_DMA\n");
13651354

13661355
return 0;
1367-
1368-
err_dma_unregister:
1369-
dma_async_device_unregister(&priv->slave);
1370-
err_clk_disable:
1371-
clk_disable_unprepare(priv->clk);
1372-
return ret;
13731356
}
13741357

13751358
static void sun4i_dma_remove(struct platform_device *pdev)
@@ -1380,9 +1363,6 @@ static void sun4i_dma_remove(struct platform_device *pdev)
13801363
disable_irq(priv->irq);
13811364

13821365
of_dma_controller_free(pdev->dev.of_node);
1383-
dma_async_device_unregister(&priv->slave);
1384-
1385-
clk_disable_unprepare(priv->clk);
13861366
}
13871367

13881368
static struct sun4i_dma_config sun4i_a10_dma_cfg = {

0 commit comments

Comments
 (0)