From: Alain Volmat <alain.volmat@foss.st.com>
To: Pei Xiao <xiaopei01@kylinos.cn>
Cc: <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>, <broonie@kernel.org>,
<Frank.Li@nxp.com>, <amelie.delaunay@foss.st.com>
Subject: Re: [Linux-stm32] [PATCH v5 13/17] spi: stm32: Simplify clock handling with devm_clk_get_enabled()
Date: Thu, 19 Mar 2026 16:52:17 +0100 [thread overview]
Message-ID: <abwbsdBCbNZniGPO@gnbcxd0016.gnb.st.com> (raw)
In-Reply-To: <c8259f582596fd08541b94dce5dbb4cae513e295.1773885292.git.xiaopei01@kylinos.cn>
Hello,
thanks for your patch.
On Thu, Mar 19, 2026 at 10:04:09AM +0800, 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>
Acked-by: Alain Volmat <alain.volmat@foss.st.com>
> ---
> drivers/spi/spi-stm32.c | 62 +++++++++++------------------------------
> 1 file changed, 17 insertions(+), 45 deletions(-)
>
> diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
> index 8a7f5a10d4af..be88e62075af 100644
> --- a/drivers/spi/spi-stm32.c
> +++ b/drivers/spi/spi-stm32.c
> @@ -2360,25 +2360,20 @@ 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");
> platform_set_drvdata(pdev, ctrl);
>
> spi = spi_controller_get_devdata(ctrl);
> @@ -2409,32 +2404,18 @@ 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)) {
> - ret = dev_err_probe(&pdev->dev, PTR_ERR(rst),
> - "failed to get reset\n");
> - goto err_clk_disable;
> - }
> + 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 +2442,8 @@ 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);
>
> ctrl->auto_runtime_pm = true;
> ctrl->bus_num = pdev->id;
> @@ -2490,8 +2468,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 +2556,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 +2585,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);
> }
>
> --
> 2.25.1
>
> _______________________________________________
> Linux-stm32 mailing list
> Linux-stm32@st-md-mailman.stormreply.com
> https://st-md-mailman.stormreply.com/mailman/listinfo/linux-stm32
Regards,
Alain
next prev parent reply other threads:[~2026-03-19 15:52 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-19 2:03 [PATCH v5 00/17] cleanup in spi by use devm_clk_get_enabled Pei Xiao
2026-03-19 2:03 ` [PATCH v5 01/17] spi: axiado: Simplify clock management with devm_clk_get_enabled() Pei Xiao
2026-03-23 19:38 ` Mark Brown
2026-03-19 2:03 ` [PATCH v5 02/17] spi: bcm63xx-hsspi: Simplify clock handling " Pei Xiao
2026-03-19 2:03 ` [PATCH v5 03/17] spi: bcmbca-hsspi: " Pei Xiao
2026-03-19 2:04 ` [PATCH v5 04/17] spi: img-spfi: " Pei Xiao
2026-03-23 19:40 ` Mark Brown
2026-03-19 2:04 ` [PATCH v5 05/17] spi: imx: " Pei Xiao
2026-03-23 19:41 ` Mark Brown
2026-03-19 2:04 ` [PATCH v5 06/17] spi: npcm-pspi: " Pei Xiao
2026-03-19 2:04 ` [PATCH v5 07/17] spi: orion: " Pei Xiao
2026-03-23 19:42 ` Mark Brown
2026-03-19 2:04 ` [PATCH v5 08/17] spi: rockchip-sfc: " Pei Xiao
2026-03-23 19:43 ` Mark Brown
2026-03-19 2:04 ` [PATCH v5 09/17] spi: sifive: " Pei Xiao
2026-03-19 2:04 ` [PATCH v5 10/17] spi: slave-mt27xx: " Pei Xiao
2026-03-19 18:30 ` Mark Brown
2026-03-19 2:04 ` [PATCH v5 11/17] spi: st: " Pei Xiao
2026-03-20 8:39 ` kernel test robot
2026-03-19 2:04 ` [PATCH v5 12/17] spi: stm32-qspi: " Pei Xiao
2026-03-23 19:44 ` Mark Brown
2026-03-19 2:04 ` [PATCH v5 13/17] spi: stm32: " Pei Xiao
2026-03-19 9:48 ` Amelie Delaunay
2026-03-19 15:52 ` Alain Volmat [this message]
2026-03-19 2:04 ` [PATCH v5 14/17] spi: sunplus-sp7021: " Pei Xiao
2026-03-19 2:04 ` [PATCH v5 15/17] spi: uniphier: " Pei Xiao
2026-03-23 21:49 ` Mark Brown
2026-03-19 2:04 ` [PATCH v5 16/17] spi: zynq-qspi: " Pei Xiao
2026-03-19 2:04 ` [PATCH v5 17/17] spi: zynqmp-gqspi: " Pei Xiao
2026-03-23 19:46 ` Mark Brown
2026-03-23 19:47 ` (subset) [PATCH v5 00/17] cleanup in spi by use devm_clk_get_enabled Mark Brown
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=abwbsdBCbNZniGPO@gnbcxd0016.gnb.st.com \
--to=alain.volmat@foss.st.com \
--cc=Frank.Li@nxp.com \
--cc=amelie.delaunay@foss.st.com \
--cc=broonie@kernel.org \
--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