From: Amelie Delaunay <amelie.delaunay@foss.st.com>
To: Pei Xiao <xiaopei01@kylinos.cn>, <linux-spi@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>, <imx@lists.linux.dev>,
<openbmc@lists.ozlabs.org>, <linux-rockchip@lists.infradead.org>,
<linux-riscv@lists.infradead.org>,
<linux-mediatek@lists.infradead.org>,
<linux-stm32@st-md-mailman.stormreply.com>
Subject: Re: [Linux-stm32] [PATCH v4 13/17] spi: stm32: Simplify clock handling with devm_clk_get_enabled()
Date: Wed, 18 Mar 2026 18:20:11 +0100 [thread overview]
Message-ID: <ae1b9767-574d-418a-84d9-8bc128a9e500@foss.st.com> (raw)
In-Reply-To: <cb88610059a9b20a9f2ffcd03cd77fecbecf7eaf.1773801401.git.xiaopei01@kylinos.cn>
Hi,
On 3/18/26 03:40, Pei Xiao wrote:
> Replace devm_clk_get() followed by clk_prepare_enable() with
> devm_clk_get_enabled() for the clock. This removes the need for
> explicit clock enable and disable calls, as the managed API automatically
> handles clock disabling on device removal or probe failure.
>
> Remove the now-unnecessary clk_disable_unprepare() calls from the probe
> error paths and the remove callback. Also simplify error handling by
> using dev_err_probe().
>
> Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
> ---
> drivers/spi/spi-stm32.c | 61 ++++++++++++-----------------------------
> 1 file changed, 18 insertions(+), 43 deletions(-)
>
> diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
> index 8a7f5a10d4af..ee5092bc5956 100644
> --- a/drivers/spi/spi-stm32.c
> +++ b/drivers/spi/spi-stm32.c
> @@ -2360,25 +2360,21 @@ static int stm32_spi_probe(struct platform_device *pdev)
> int ret;
>
> cfg = of_device_get_match_data(&pdev->dev);
> - if (!cfg) {
> - dev_err(&pdev->dev, "Failed to get match data for platform\n");
> - return -ENODEV;
> - }
> + if (!cfg)
> + return dev_err_probe(&pdev->dev, -ENODEV,
> + "Failed to get match data for platform\n");
>
> device_mode = of_property_read_bool(np, "spi-slave");
> - if (!cfg->has_device_mode && device_mode) {
> - dev_err(&pdev->dev, "spi-slave not supported\n");
> - return -EPERM;
> - }
> + if (!cfg->has_device_mode && device_mode)
> + return dev_err_probe(&pdev->dev, -EPERM, "spi-slave not supported\n");
>
> if (device_mode)
> ctrl = devm_spi_alloc_target(&pdev->dev, sizeof(struct stm32_spi));
> else
> ctrl = devm_spi_alloc_host(&pdev->dev, sizeof(struct stm32_spi));
> - if (!ctrl) {
> - dev_err(&pdev->dev, "spi controller allocation failed\n");
> - return -ENOMEM;
> - }
> + if (!ctrl)
> + return dev_err_probe(&pdev->dev, -ENOMEM,
> + "spi controller allocation failed\n");
it fits on single line
+ return dev_err_probe(&pdev->dev, -ENOMEM, "spi controller allocation
failed\n");
> platform_set_drvdata(pdev, ctrl);
>
> spi = spi_controller_get_devdata(ctrl);
> @@ -2409,32 +2405,19 @@ static int stm32_spi_probe(struct platform_device *pdev)
> return ret;
> }
>
> - spi->clk = devm_clk_get(&pdev->dev, NULL);
> - if (IS_ERR(spi->clk)) {
> - ret = PTR_ERR(spi->clk);
> - dev_err(&pdev->dev, "clk get failed: %d\n", ret);
> - return ret;
> - }
> + spi->clk = devm_clk_get_enabled(&pdev->dev, NULL);
> + if (IS_ERR(spi->clk))
> + return dev_err_probe(&pdev->dev, PTR_ERR(spi->clk), "clk enabled failed\n");
>
> - ret = clk_prepare_enable(spi->clk);
> - if (ret) {
> - dev_err(&pdev->dev, "clk enable failed: %d\n", ret);
> - return ret;
> - }
> spi->clk_rate = clk_get_rate(spi->clk);
> - if (!spi->clk_rate) {
> - dev_err(&pdev->dev, "clk rate = 0\n");
> - ret = -EINVAL;
> - goto err_clk_disable;
> - }
> + if (!spi->clk_rate)
> + return dev_err_probe(&pdev->dev, -EINVAL, "clk rate = 0\n");
>
> rst = devm_reset_control_get_optional_exclusive(&pdev->dev, NULL);
> if (rst) {
> - if (IS_ERR(rst)) {
> + if (IS_ERR(rst))
> ret = dev_err_probe(&pdev->dev, PTR_ERR(rst),
> "failed to get reset\n");
> - goto err_clk_disable;
> - }
Here you change the behavior: it should return dev_err_probe(...) (on
single line too)
+ if (IS_ERR(rst))
+ return dev_err_probe(&pdev->dev, PTR_ERR(rst), "failed to get
reset\n");
>
> reset_control_assert(rst);
> udelay(2);
> @@ -2461,11 +2444,9 @@ static int stm32_spi_probe(struct platform_device *pdev)
> dev_dbg(spi->dev, "one message max size %d\n", spi->t_size_max);
>
> ret = spi->cfg->config(spi);
> - if (ret) {
> - dev_err(&pdev->dev, "controller configuration failed: %d\n",
> - ret);
> - goto err_clk_disable;
> - }
> + if (ret)
> + return dev_err_probe(&pdev->dev, ret,
> + "controller configuration failed: %d\n", ret);
it fits on single line too here.
>
> ctrl->auto_runtime_pm = true;
> ctrl->bus_num = pdev->id;
> @@ -2490,8 +2471,7 @@ static int stm32_spi_probe(struct platform_device *pdev)
> dev_info(&pdev->dev, "tx dma disabled\n");
> spi->dma_tx = NULL;
> } else {
> - dev_err_probe(&pdev->dev, ret, "failed to request tx dma channel\n");
> - goto err_clk_disable;
> + return dev_err_probe(&pdev->dev, ret, "failed to request tx dma channel\n");
> }
> } else {
> ctrl->dma_tx = spi->dma_tx;
> @@ -2579,8 +2559,6 @@ static int stm32_spi_probe(struct platform_device *pdev)
> err_dma_tx_release:
> if (spi->dma_tx)
> dma_release_channel(spi->dma_tx);
> -err_clk_disable:
> - clk_disable_unprepare(spi->clk);
>
> return ret;
> }
> @@ -2610,9 +2588,6 @@ static void stm32_spi_remove(struct platform_device *pdev)
> gen_pool_free(spi->sram_pool, (unsigned long)spi->sram_rx_buf,
> spi->sram_rx_buf_size);
>
> - clk_disable_unprepare(spi->clk);
> -
> -
> pinctrl_pm_select_sleep_state(&pdev->dev);
> }
>
next prev parent reply other threads:[~2026-03-18 17:20 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-18 2:39 [PATCH v4 00/17] cleanup in spi by use devm_clk_get_enabled Pei Xiao
2026-03-18 2:39 ` [PATCH v4 01/17] spi: axiado: Simplify clock management with devm_clk_get_enabled() Pei Xiao
2026-03-18 2:39 ` [PATCH v4 02/17] spi: bcm63xx-hsspi: Simplify clock handling " Pei Xiao
2026-03-18 2:39 ` [PATCH v4 03/17] spi: bcmbca-hsspi: " Pei Xiao
2026-03-18 2:39 ` [PATCH v4 04/17] spi: img-spfi: " Pei Xiao
2026-03-18 2:39 ` [PATCH v4 05/17] spi: imx: " Pei Xiao
2026-03-18 13:45 ` Frank Li
2026-03-18 2:39 ` [PATCH v4 06/17] spi: npcm-pspi: " Pei Xiao
2026-03-18 2:39 ` [PATCH v4 07/17] spi: orion: " Pei Xiao
2026-03-18 2:39 ` [PATCH v4 08/17] spi: rockchip-sfc: " Pei Xiao
2026-03-18 2:39 ` [PATCH v4 09/17] spi: sifive: " Pei Xiao
2026-03-18 2:40 ` [PATCH v4 10/17] spi: slave-mt27xx: " Pei Xiao
2026-03-18 2:40 ` [PATCH v4 11/17] spi: st: " Pei Xiao
2026-03-18 2:40 ` [PATCH v4 12/17] spi: stm32-qspi: " Pei Xiao
2026-03-18 2:40 ` [PATCH v4 13/17] spi: stm32: " Pei Xiao
2026-03-18 17:20 ` Amelie Delaunay [this message]
2026-03-18 2:40 ` [PATCH v4 14/17] spi: sunplus-sp7021: " Pei Xiao
2026-03-18 2:40 ` [PATCH v4 15/17] spi: uniphier: " Pei Xiao
2026-03-18 2:40 ` [PATCH v4 16/17] spi: zynq-qspi: " Pei Xiao
2026-03-18 2:40 ` [PATCH v4 17/17] spi: zynqmp-gqspi: " Pei Xiao
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=ae1b9767-574d-418a-84d9-8bc128a9e500@foss.st.com \
--to=amelie.delaunay@foss.st.com \
--cc=imx@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=linux-spi@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=openbmc@lists.ozlabs.org \
--cc=xiaopei01@kylinos.cn \
/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