mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-07-22 02:17:36 -04:00
spi: slave-mt27xx: switch to managed controller allocation
Switch to device managed controller allocation to simplify error handling and to avoid having to take another reference during deregistration. Signed-off-by: Johan Hovold <johan@kernel.org> Link: https://patch.msgid.link/20260505072909.618363-10-johan@kernel.org Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
@@ -388,11 +388,9 @@ static int mtk_spi_slave_probe(struct platform_device *pdev)
|
||||
int irq, ret;
|
||||
const struct of_device_id *of_id;
|
||||
|
||||
ctlr = spi_alloc_target(&pdev->dev, sizeof(*mdata));
|
||||
if (!ctlr) {
|
||||
dev_err(&pdev->dev, "failed to alloc spi target\n");
|
||||
ctlr = devm_spi_alloc_target(&pdev->dev, sizeof(*mdata));
|
||||
if (!ctlr)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
ctlr->auto_runtime_pm = true;
|
||||
ctlr->mode_bits = SPI_CPOL | SPI_CPHA;
|
||||
@@ -406,8 +404,7 @@ static int mtk_spi_slave_probe(struct platform_device *pdev)
|
||||
of_id = of_match_node(mtk_spi_slave_of_match, pdev->dev.of_node);
|
||||
if (!of_id) {
|
||||
dev_err(&pdev->dev, "failed to probe of_node\n");
|
||||
ret = -EINVAL;
|
||||
goto err_put_ctlr;
|
||||
return -EINVAL;
|
||||
}
|
||||
mdata = spi_controller_get_devdata(ctlr);
|
||||
mdata->dev_comp = of_id->data;
|
||||
@@ -420,35 +417,31 @@ static int mtk_spi_slave_probe(struct platform_device *pdev)
|
||||
init_completion(&mdata->xfer_done);
|
||||
mdata->dev = &pdev->dev;
|
||||
mdata->base = devm_platform_ioremap_resource(pdev, 0);
|
||||
if (IS_ERR(mdata->base)) {
|
||||
ret = PTR_ERR(mdata->base);
|
||||
goto err_put_ctlr;
|
||||
}
|
||||
if (IS_ERR(mdata->base))
|
||||
return PTR_ERR(mdata->base);
|
||||
|
||||
irq = platform_get_irq(pdev, 0);
|
||||
if (irq < 0) {
|
||||
ret = irq;
|
||||
goto err_put_ctlr;
|
||||
}
|
||||
if (irq < 0)
|
||||
return irq;
|
||||
|
||||
ret = devm_request_irq(&pdev->dev, irq, mtk_spi_slave_interrupt,
|
||||
IRQF_TRIGGER_NONE, dev_name(&pdev->dev), ctlr);
|
||||
if (ret) {
|
||||
dev_err(&pdev->dev, "failed to register irq (%d)\n", ret);
|
||||
goto err_put_ctlr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
mdata->spi_clk = devm_clk_get(&pdev->dev, "spi");
|
||||
if (IS_ERR(mdata->spi_clk)) {
|
||||
ret = PTR_ERR(mdata->spi_clk);
|
||||
dev_err(&pdev->dev, "failed to get spi-clk: %d\n", ret);
|
||||
goto err_put_ctlr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = clk_prepare_enable(mdata->spi_clk);
|
||||
if (ret < 0) {
|
||||
dev_err(&pdev->dev, "failed to enable spi_clk (%d)\n", ret);
|
||||
goto err_put_ctlr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
pm_runtime_enable(&pdev->dev);
|
||||
@@ -465,8 +458,6 @@ static int mtk_spi_slave_probe(struct platform_device *pdev)
|
||||
|
||||
err_disable_runtime_pm:
|
||||
pm_runtime_disable(&pdev->dev);
|
||||
err_put_ctlr:
|
||||
spi_controller_put(ctlr);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -475,13 +466,9 @@ static void mtk_spi_slave_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct spi_controller *ctlr = platform_get_drvdata(pdev);
|
||||
|
||||
spi_controller_get(ctlr);
|
||||
|
||||
spi_unregister_controller(ctlr);
|
||||
|
||||
pm_runtime_disable(&pdev->dev);
|
||||
|
||||
spi_controller_put(ctlr);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PM_SLEEP
|
||||
|
||||
Reference in New Issue
Block a user