[PATCH 11/19] spi: fsl: switch to managed controller allocation

From: Johan Hovold

Date: Wed Apr 29 2026 - 05:19:58 EST


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@xxxxxxxxxx>
---
drivers/spi/spi-fsl-spi.c | 14 ++------------
1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/drivers/spi/spi-fsl-spi.c b/drivers/spi/spi-fsl-spi.c
index 1252c41c206f..e45816ef7b65 100644
--- a/drivers/spi/spi-fsl-spi.c
+++ b/drivers/spi/spi-fsl-spi.c
@@ -535,7 +535,7 @@ static struct spi_controller *fsl_spi_probe(struct device *dev,
u32 regval;
int ret = 0;

- host = spi_alloc_host(dev, sizeof(struct mpc8xxx_spi));
+ host = devm_spi_alloc_host(dev, sizeof(struct mpc8xxx_spi));
if (host == NULL) {
ret = -ENOMEM;
goto err;
@@ -559,7 +559,7 @@ static struct spi_controller *fsl_spi_probe(struct device *dev,

ret = fsl_spi_cpm_init(mpc8xxx_spi);
if (ret)
- goto err_cpm_init;
+ goto err;

mpc8xxx_spi->reg_base = devm_ioremap_resource(dev, mem);
if (IS_ERR(mpc8xxx_spi->reg_base)) {
@@ -625,8 +625,6 @@ static struct spi_controller *fsl_spi_probe(struct device *dev,

err_probe:
fsl_spi_cpm_free(mpc8xxx_spi);
-err_cpm_init:
- spi_controller_put(host);
err:
return ERR_PTR(ret);
}
@@ -705,13 +703,9 @@ static void of_fsl_spi_remove(struct platform_device *ofdev)
struct spi_controller *host = platform_get_drvdata(ofdev);
struct mpc8xxx_spi *mpc8xxx_spi = spi_controller_get_devdata(host);

- spi_controller_get(host);
-
spi_unregister_controller(host);

fsl_spi_cpm_free(mpc8xxx_spi);
-
- spi_controller_put(host);
}

static struct platform_driver of_fsl_spi_driver = {
@@ -757,13 +751,9 @@ static void plat_mpc8xxx_spi_remove(struct platform_device *pdev)
struct spi_controller *host = platform_get_drvdata(pdev);
struct mpc8xxx_spi *mpc8xxx_spi = spi_controller_get_devdata(host);

- spi_controller_get(host);
-
spi_unregister_controller(host);

fsl_spi_cpm_free(mpc8xxx_spi);
-
- spi_controller_put(host);
}

MODULE_ALIAS("platform:mpc8xxx_spi");
--
2.53.0