mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-07-22 02:17:36 -04:00
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 <johan@kernel.org> Link: https://patch.msgid.link/20260429091333.165363-10-johan@kernel.org Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user