From: Johan Hovold Date: Wed, 29 Apr 2026 09:13:23 +0000 (+0200) Subject: spi: dln2: switch to managed controller allocation X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6bd505e710aa612cf57f7894a10d00c99d600226;p=thirdparty%2Fkernel%2Flinux.git spi: dln2: 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 Link: https://patch.msgid.link/20260429091333.165363-10-johan@kernel.org Signed-off-by: Mark Brown --- diff --git a/drivers/spi/spi-dln2.c b/drivers/spi/spi-dln2.c index 392f0d05f5082..8333dda7d1e8b 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 @@ exit_register: 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