From: Johan Hovold <johan@kernel.org>
To: Mark Brown <broonie@kernel.org>
Cc: Frank Li <Frank.Li@nxp.com>,
Sascha Hauer <s.hauer@pengutronix.de>,
Heiko Stuebner <heiko@sntech.de>,
Laxman Dewangan <ldewangan@nvidia.com>,
linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
Johan Hovold <johan@kernel.org>
Subject: [PATCH 5/5] spi: rockchip: switch to managed controller allocation
Date: Mon, 23 Mar 2026 11:49:48 +0100 [thread overview]
Message-ID: <20260323104948.844583-6-johan@kernel.org> (raw)
In-Reply-To: <20260323104948.844583-1-johan@kernel.org>
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>
---
drivers/spi/spi-rockchip.c | 36 +++++++++++++-----------------------
1 file changed, 13 insertions(+), 23 deletions(-)
diff --git a/drivers/spi/spi-rockchip.c b/drivers/spi/spi-rockchip.c
index eb1992b4178e..14cd1b9d9793 100644
--- a/drivers/spi/spi-rockchip.c
+++ b/drivers/spi/spi-rockchip.c
@@ -767,9 +767,9 @@ static int rockchip_spi_probe(struct platform_device *pdev)
target_mode = of_property_read_bool(np, "spi-slave");
if (target_mode)
- ctlr = spi_alloc_target(&pdev->dev, sizeof(struct rockchip_spi));
+ ctlr = devm_spi_alloc_target(&pdev->dev, sizeof(*rs));
else
- ctlr = spi_alloc_host(&pdev->dev, sizeof(struct rockchip_spi));
+ ctlr = devm_spi_alloc_host(&pdev->dev, sizeof(*rs));
if (!ctlr)
return -ENOMEM;
@@ -780,35 +780,31 @@ static int rockchip_spi_probe(struct platform_device *pdev)
/* Get basic io resource and map it */
rs->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &mem);
- if (IS_ERR(rs->regs)) {
- ret = PTR_ERR(rs->regs);
- goto err_put_ctlr;
- }
+ if (IS_ERR(rs->regs))
+ return PTR_ERR(rs->regs);
rs->apb_pclk = devm_clk_get_enabled(&pdev->dev, "apb_pclk");
if (IS_ERR(rs->apb_pclk)) {
- ret = dev_err_probe(&pdev->dev, PTR_ERR(rs->apb_pclk),
- "Failed to get apb_pclk\n");
- goto err_put_ctlr;
+ return dev_err_probe(&pdev->dev, PTR_ERR(rs->apb_pclk),
+ "Failed to get apb_pclk\n");
}
rs->spiclk = devm_clk_get_enabled(&pdev->dev, "spiclk");
if (IS_ERR(rs->spiclk)) {
- ret = dev_err_probe(&pdev->dev, PTR_ERR(rs->spiclk),
- "Failed to get spi_pclk\n");
- goto err_put_ctlr;
+ return dev_err_probe(&pdev->dev, PTR_ERR(rs->spiclk),
+ "Failed to get spi_pclk\n");
}
spi_enable_chip(rs, false);
ret = platform_get_irq(pdev, 0);
if (ret < 0)
- goto err_put_ctlr;
+ return ret;
ret = devm_request_irq(&pdev->dev, ret, rockchip_spi_isr, 0,
dev_name(&pdev->dev), ctlr);
if (ret)
- goto err_put_ctlr;
+ return ret;
rs->dev = &pdev->dev;
rs->freq = clk_get_rate(rs->spiclk);
@@ -830,10 +826,8 @@ static int rockchip_spi_probe(struct platform_device *pdev)
}
rs->fifo_len = get_fifo_len(rs);
- if (!rs->fifo_len) {
- ret = dev_err_probe(&pdev->dev, -EINVAL, "Failed to get fifo length\n");
- goto err_put_ctlr;
- }
+ if (!rs->fifo_len)
+ return dev_err_probe(&pdev->dev, -EINVAL, "Failed to get fifo length\n");
pm_runtime_set_autosuspend_delay(&pdev->dev, ROCKCHIP_AUTOSUSPEND_TIMEOUT);
pm_runtime_use_autosuspend(&pdev->dev);
@@ -924,15 +918,13 @@ static int rockchip_spi_probe(struct platform_device *pdev)
dma_release_channel(ctlr->dma_tx);
err_disable_pm_runtime:
pm_runtime_disable(&pdev->dev);
-err_put_ctlr:
- spi_controller_put(ctlr);
return ret;
}
static void rockchip_spi_remove(struct platform_device *pdev)
{
- struct spi_controller *ctlr = spi_controller_get(platform_get_drvdata(pdev));
+ struct spi_controller *ctlr = platform_get_drvdata(pdev);
pm_runtime_get_sync(&pdev->dev);
@@ -946,8 +938,6 @@ static void rockchip_spi_remove(struct platform_device *pdev)
dma_release_channel(ctlr->dma_tx);
if (ctlr->dma_rx)
dma_release_channel(ctlr->dma_rx);
-
- spi_controller_put(ctlr);
}
#ifdef CONFIG_PM_SLEEP
--
2.52.0
prev parent reply other threads:[~2026-03-23 10:50 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-23 10:49 [PATCH 0/5] spi: imx: fix use-after-free on unbind Johan Hovold
2026-03-23 10:49 ` [PATCH 1/5] " Johan Hovold
2026-03-23 11:00 ` Marc Kleine-Budde
2026-03-23 11:20 ` Johan Hovold
2026-03-23 11:57 ` Marc Kleine-Budde
2026-03-23 13:59 ` Johan Hovold
2026-03-23 14:47 ` Marc Kleine-Budde
2026-03-23 15:41 ` Johan Hovold
2026-03-23 10:49 ` [PATCH 2/5] spi: imx: switch to managed controller allocation Johan Hovold
2026-03-23 10:49 ` [PATCH 3/5] spi: tegra20-slink: " Johan Hovold
2026-03-23 10:49 ` [PATCH 4/5] spi: rockchip: fix controller deregistration Johan Hovold
2026-03-23 16:35 ` Mark Brown
2026-03-23 16:51 ` Johan Hovold
2026-03-23 17:02 ` Mark Brown
2026-03-24 8:09 ` Johan Hovold
2026-03-23 10:49 ` Johan Hovold [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260323104948.844583-6-johan@kernel.org \
--to=johan@kernel.org \
--cc=Frank.Li@nxp.com \
--cc=broonie@kernel.org \
--cc=heiko@sntech.de \
--cc=ldewangan@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=s.hauer@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox