[PATCH 09/19] spi: dln2: switch to managed controller allocation
From: Johan Hovold
Date: Wed Apr 29 2026 - 05:14:32 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-dln2.c | 26 +++++++++-----------------
1 file changed, 9 insertions(+), 17 deletions(-)
diff --git a/drivers/spi/spi-dln2.c b/drivers/spi/spi-dln2.c
index 392f0d05f508..8333dda7d1e8 100644
--- a/drivers/spi/spi-dln2.c
+++ b/drivers/spi/spi-dln2.c
@@ -684,7 +684,7 @@ static int dln2_spi_probe(struct platform_device *pdev)
struct dln2_platform_data *pdata = dev_get_platdata(&pdev->dev);
int ret;
- host = spi_alloc_host(&pdev->dev, sizeof(*dln2));
+ host = devm_spi_alloc_host(&pdev->dev, sizeof(*dln2));
if (!host)
return -ENOMEM;
@@ -693,10 +693,8 @@ static int dln2_spi_probe(struct platform_device *pdev)
dln2 = spi_controller_get_devdata(host);
dln2->buf = devm_kmalloc(&pdev->dev, DLN2_SPI_BUF_SIZE, GFP_KERNEL);
- if (!dln2->buf) {
- ret = -ENOMEM;
- goto exit_free_host;
- }
+ if (!dln2->buf)
+ return -ENOMEM;
dln2->host = host;
dln2->pdev = pdev;
@@ -709,13 +707,13 @@ static int dln2_spi_probe(struct platform_device *pdev)
ret = dln2_spi_enable(dln2, false);
if (ret < 0) {
dev_err(&pdev->dev, "Failed to disable SPI module\n");
- goto exit_free_host;
+ return ret;
}
ret = dln2_spi_get_cs_num(dln2, &host->num_chipselect);
if (ret < 0) {
dev_err(&pdev->dev, "Failed to get number of CS pins\n");
- goto exit_free_host;
+ return ret;
}
ret = dln2_spi_get_speed_range(dln2,
@@ -723,20 +721,20 @@ static int dln2_spi_probe(struct platform_device *pdev)
&host->max_speed_hz);
if (ret < 0) {
dev_err(&pdev->dev, "Failed to read bus min/max freqs\n");
- goto exit_free_host;
+ return ret;
}
ret = dln2_spi_get_supported_frame_sizes(dln2,
&host->bits_per_word_mask);
if (ret < 0) {
dev_err(&pdev->dev, "Failed to read supported frame sizes\n");
- goto exit_free_host;
+ return ret;
}
ret = dln2_spi_cs_enable_all(dln2, true);
if (ret < 0) {
dev_err(&pdev->dev, "Failed to enable CS pins\n");
- goto exit_free_host;
+ return ret;
}
host->bus_num = -1;
@@ -749,7 +747,7 @@ static int dln2_spi_probe(struct platform_device *pdev)
ret = dln2_spi_enable(dln2, true);
if (ret < 0) {
dev_err(&pdev->dev, "Failed to enable SPI module\n");
- goto exit_free_host;
+ return ret;
}
pm_runtime_set_autosuspend_delay(&pdev->dev,
@@ -772,8 +770,6 @@ static int dln2_spi_probe(struct platform_device *pdev)
if (dln2_spi_enable(dln2, false) < 0)
dev_err(&pdev->dev, "Failed to disable SPI module\n");
-exit_free_host:
- spi_controller_put(host);
return ret;
}
@@ -783,16 +779,12 @@ static void dln2_spi_remove(struct platform_device *pdev)
struct spi_controller *host = platform_get_drvdata(pdev);
struct dln2_spi *dln2 = spi_controller_get_devdata(host);
- spi_controller_get(host);
-
spi_unregister_controller(host);
pm_runtime_disable(&pdev->dev);
if (dln2_spi_enable(dln2, false) < 0)
dev_err(&pdev->dev, "Failed to disable SPI module\n");
-
- spi_controller_put(host);
}
#ifdef CONFIG_PM_SLEEP
--
2.53.0