From: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
To: linux-rockchip@lists.infradead.org, linux-sound@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Pei Xiao <xiaopei01@kylinos.cn>
Subject: Re: [PATCH 2/2] ASOC: rockchip: Use helper function devm_clk_get_enabled()
Date: Fri, 06 Jun 2025 10:26:36 +0200 [thread overview]
Message-ID: <2895073.PYKUYFuaPT@workhorse> (raw)
In-Reply-To: <3f589ddf-e421-494f-85e5-1adebd19d03a@kylinos.cn>
On Friday, 6 June 2025 05:27:13 Central European Summer Time Pei Xiao wrote:
>
> 在 2025/6/5 01:42, Nicolas Frattaroli 写道:
> > On Wednesday, 4 June 2025 05:13:30 Central European Summer Time Pei Xiao wrote:
> >> Since commit 7ef9651e9792 ("clk: Provide new devm_clk helpers for prepared
> >> and enabled clocks"), devm_clk_get() and clk_prepare_enable() can now be
> >> replaced by devm_clk_get_enabled() when driver enables the clocks for the
> >> whole lifetime of the device. Moreover, it is no longer necessary to
> >> unprepare and disable the clocks explicitly.
> >>
> >> Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
> >> ---
> >> sound/soc/rockchip/rockchip_sai.c | 8 +-------
> >> 1 file changed, 1 insertion(+), 7 deletions(-)
> >>
> >> diff --git a/sound/soc/rockchip/rockchip_sai.c b/sound/soc/rockchip/rockchip_sai.c
> >> index 79b04770da1c..2ec675708681 100644
> >> --- a/sound/soc/rockchip/rockchip_sai.c
> >> +++ b/sound/soc/rockchip/rockchip_sai.c
> >> @@ -1448,16 +1448,12 @@ static int rockchip_sai_probe(struct platform_device *pdev)
> >> "Failed to get mclk\n");
> >> }
> >>
> >> - sai->hclk = devm_clk_get(&pdev->dev, "hclk");
> >> + sai->hclk = devm_clk_get_enabled(&pdev->dev, "hclk");
> >> if (IS_ERR(sai->hclk)) {
> >> return dev_err_probe(&pdev->dev, PTR_ERR(sai->hclk),
> >> "Failed to get hclk\n");
> >> }
> >>
> >> - ret = clk_prepare_enable(sai->hclk);
> >> - if (ret)
> >> - return dev_err_probe(&pdev->dev, ret, "Failed to enable hclk\n");
> >> -
> >> regmap_read(sai->regmap, SAI_VERSION, &sai->version);
> >>
> >> ret = rockchip_sai_init_dai(sai, res, &dai);
> >> @@ -1512,8 +1508,6 @@ static int rockchip_sai_probe(struct platform_device *pdev)
> >> if (pm_runtime_put(&pdev->dev))
> >> rockchip_sai_runtime_suspend(&pdev->dev);
> >> err_disable_hclk:
> >> - clk_disable_unprepare(sai->hclk);
> >> -
> >> return ret;
> >> }
> >>
> >>
> > Please get rid of the err_disable_hclk label, and change the
> >
> > goto err_disable_hclk;
> >
> > in the resume failure condition to a
> >
> > return ret;
> May I ask, could we use the dev_err_probe function instead?
>
> return dev_err_probe(&pdev->dev, ret, "Failed to initialize DAI\n");
Absolutely, dev_err_probe states the following in its documentation:
Using this helper in your probe function is totally fine even if @err
is known to never be -EPROBE_DEFER.
This means you can use it for every error case in the probe function.
>
>
> @@ -1441,28 +1441,22 @@ static int rockchip_sai_probe(struct platform_device *pdev)
> "Failed to get mclk\n");
> }
>
> - sai->hclk = devm_clk_get(&pdev->dev, "hclk");
> + sai->hclk = devm_clk_get_enabled(&pdev->dev, "hclk");
> if (IS_ERR(sai->hclk)) {
> return dev_err_probe(&pdev->dev, PTR_ERR(sai->hclk),
> "Failed to get hclk\n");
> }
>
> - ret = clk_prepare_enable(sai->hclk);
> - if (ret)
> - return dev_err_probe(&pdev->dev, ret, "Failed to enable hclk\n");
> -
> regmap_read(sai->regmap, SAI_VERSION, &sai->version);
>
> ret = rockchip_sai_init_dai(sai, res, &dai);
> if (ret) {
> - dev_err(&pdev->dev, "Failed to initialize DAI: %d\n", ret);
> - goto err_disable_hclk;
> + return dev_err_probe(&pdev->dev, ret, "Failed to initialize DAI\n");
> }
This would now be a one-line statement in the if branch, so checkpatch will
advise you to remove the redundant { } from the if, so that it becomes
if (ret)
return dev_err_probe(&pdev->dev, ret, "Failed to initialize DAI\n");
You can run `./scripts/checkpatch.pl` on either a git commit range or a
patch file, and it'll let you know. If you use b4, it'll run that
script with some recommended flags on all commits in your series with
`b4 prep --check`.
>
> ret = rockchip_sai_parse_paths(sai, node);
> if (ret) {
> - dev_err(&pdev->dev, "Failed to parse paths: %d\n", ret);
> - goto err_disable_hclk;
> + return dev_err_probe(&pdev->dev, ret, "Failed to parse paths\n");
> }
Same here
>
> /*
> @@ -1475,8 +1469,7 @@ static int rockchip_sai_probe(struct platform_device *pdev)
> pm_runtime_get_noresume(&pdev->dev);
> ret = rockchip_sai_runtime_resume(&pdev->dev);
> if (ret) {
> - dev_err(&pdev->dev, "Failed to resume device: %pe\n", ERR_PTR(ret));
> - goto err_disable_hclk;
> + return dev_err_probe(&pdev->dev, ret, "Failed to resume device\n");
> }
Same here
>
> ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0);
> @@ -1504,8 +1497,6 @@ static int rockchip_sai_probe(struct platform_device *pdev)
> /* If we're !CONFIG_PM, we get -ENOSYS and disable manually */
> if (pm_runtime_put(&pdev->dev))
> rockchip_sai_runtime_suspend(&pdev->dev);
> -err_disable_hclk:
> - clk_disable_unprepare(sai->hclk);
>
> return ret;
> }
>
> thanks!
>
> Pei.
Kind regards,
Nicolas Frattaroli
>
> > Other than that, patch tested to be working fine.
> >
> > Kind regards,
> > Nicolas Frattaroli
> >
> >
>
WARNING: multiple messages have this Message-ID (diff)
From: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
To: linux-rockchip@lists.infradead.org, linux-sound@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Pei Xiao <xiaopei01@kylinos.cn>
Subject: Re: [PATCH 2/2] ASOC: rockchip: Use helper function devm_clk_get_enabled()
Date: Fri, 06 Jun 2025 10:26:36 +0200 [thread overview]
Message-ID: <2895073.PYKUYFuaPT@workhorse> (raw)
In-Reply-To: <3f589ddf-e421-494f-85e5-1adebd19d03a@kylinos.cn>
On Friday, 6 June 2025 05:27:13 Central European Summer Time Pei Xiao wrote:
>
> 在 2025/6/5 01:42, Nicolas Frattaroli 写道:
> > On Wednesday, 4 June 2025 05:13:30 Central European Summer Time Pei Xiao wrote:
> >> Since commit 7ef9651e9792 ("clk: Provide new devm_clk helpers for prepared
> >> and enabled clocks"), devm_clk_get() and clk_prepare_enable() can now be
> >> replaced by devm_clk_get_enabled() when driver enables the clocks for the
> >> whole lifetime of the device. Moreover, it is no longer necessary to
> >> unprepare and disable the clocks explicitly.
> >>
> >> Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
> >> ---
> >> sound/soc/rockchip/rockchip_sai.c | 8 +-------
> >> 1 file changed, 1 insertion(+), 7 deletions(-)
> >>
> >> diff --git a/sound/soc/rockchip/rockchip_sai.c b/sound/soc/rockchip/rockchip_sai.c
> >> index 79b04770da1c..2ec675708681 100644
> >> --- a/sound/soc/rockchip/rockchip_sai.c
> >> +++ b/sound/soc/rockchip/rockchip_sai.c
> >> @@ -1448,16 +1448,12 @@ static int rockchip_sai_probe(struct platform_device *pdev)
> >> "Failed to get mclk\n");
> >> }
> >>
> >> - sai->hclk = devm_clk_get(&pdev->dev, "hclk");
> >> + sai->hclk = devm_clk_get_enabled(&pdev->dev, "hclk");
> >> if (IS_ERR(sai->hclk)) {
> >> return dev_err_probe(&pdev->dev, PTR_ERR(sai->hclk),
> >> "Failed to get hclk\n");
> >> }
> >>
> >> - ret = clk_prepare_enable(sai->hclk);
> >> - if (ret)
> >> - return dev_err_probe(&pdev->dev, ret, "Failed to enable hclk\n");
> >> -
> >> regmap_read(sai->regmap, SAI_VERSION, &sai->version);
> >>
> >> ret = rockchip_sai_init_dai(sai, res, &dai);
> >> @@ -1512,8 +1508,6 @@ static int rockchip_sai_probe(struct platform_device *pdev)
> >> if (pm_runtime_put(&pdev->dev))
> >> rockchip_sai_runtime_suspend(&pdev->dev);
> >> err_disable_hclk:
> >> - clk_disable_unprepare(sai->hclk);
> >> -
> >> return ret;
> >> }
> >>
> >>
> > Please get rid of the err_disable_hclk label, and change the
> >
> > goto err_disable_hclk;
> >
> > in the resume failure condition to a
> >
> > return ret;
> May I ask, could we use the dev_err_probe function instead?
>
> return dev_err_probe(&pdev->dev, ret, "Failed to initialize DAI\n");
Absolutely, dev_err_probe states the following in its documentation:
Using this helper in your probe function is totally fine even if @err
is known to never be -EPROBE_DEFER.
This means you can use it for every error case in the probe function.
>
>
> @@ -1441,28 +1441,22 @@ static int rockchip_sai_probe(struct platform_device *pdev)
> "Failed to get mclk\n");
> }
>
> - sai->hclk = devm_clk_get(&pdev->dev, "hclk");
> + sai->hclk = devm_clk_get_enabled(&pdev->dev, "hclk");
> if (IS_ERR(sai->hclk)) {
> return dev_err_probe(&pdev->dev, PTR_ERR(sai->hclk),
> "Failed to get hclk\n");
> }
>
> - ret = clk_prepare_enable(sai->hclk);
> - if (ret)
> - return dev_err_probe(&pdev->dev, ret, "Failed to enable hclk\n");
> -
> regmap_read(sai->regmap, SAI_VERSION, &sai->version);
>
> ret = rockchip_sai_init_dai(sai, res, &dai);
> if (ret) {
> - dev_err(&pdev->dev, "Failed to initialize DAI: %d\n", ret);
> - goto err_disable_hclk;
> + return dev_err_probe(&pdev->dev, ret, "Failed to initialize DAI\n");
> }
This would now be a one-line statement in the if branch, so checkpatch will
advise you to remove the redundant { } from the if, so that it becomes
if (ret)
return dev_err_probe(&pdev->dev, ret, "Failed to initialize DAI\n");
You can run `./scripts/checkpatch.pl` on either a git commit range or a
patch file, and it'll let you know. If you use b4, it'll run that
script with some recommended flags on all commits in your series with
`b4 prep --check`.
>
> ret = rockchip_sai_parse_paths(sai, node);
> if (ret) {
> - dev_err(&pdev->dev, "Failed to parse paths: %d\n", ret);
> - goto err_disable_hclk;
> + return dev_err_probe(&pdev->dev, ret, "Failed to parse paths\n");
> }
Same here
>
> /*
> @@ -1475,8 +1469,7 @@ static int rockchip_sai_probe(struct platform_device *pdev)
> pm_runtime_get_noresume(&pdev->dev);
> ret = rockchip_sai_runtime_resume(&pdev->dev);
> if (ret) {
> - dev_err(&pdev->dev, "Failed to resume device: %pe\n", ERR_PTR(ret));
> - goto err_disable_hclk;
> + return dev_err_probe(&pdev->dev, ret, "Failed to resume device\n");
> }
Same here
>
> ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0);
> @@ -1504,8 +1497,6 @@ static int rockchip_sai_probe(struct platform_device *pdev)
> /* If we're !CONFIG_PM, we get -ENOSYS and disable manually */
> if (pm_runtime_put(&pdev->dev))
> rockchip_sai_runtime_suspend(&pdev->dev);
> -err_disable_hclk:
> - clk_disable_unprepare(sai->hclk);
>
> return ret;
> }
>
> thanks!
>
> Pei.
Kind regards,
Nicolas Frattaroli
>
> > Other than that, patch tested to be working fine.
> >
> > Kind regards,
> > Nicolas Frattaroli
> >
> >
>
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
next prev parent reply other threads:[~2025-06-06 8:30 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-04 3:13 [PATCH 0/2] Cleanup in rockchip_sai.c Pei Xiao
2025-06-04 3:13 ` Pei Xiao
2025-06-04 3:13 ` [PATCH 1/2] ASOC: rochchip: Simplify the condition logic in rockchip_sai_xfer_stop Pei Xiao
2025-06-04 3:13 ` Pei Xiao
2025-06-04 17:23 ` Nicolas Frattaroli
2025-06-04 17:23 ` Nicolas Frattaroli
2025-06-05 1:57 ` Pei Xiao
2025-06-05 1:57 ` Pei Xiao
2025-06-05 14:30 ` Nicolas Frattaroli
2025-06-05 14:30 ` Nicolas Frattaroli
2025-06-04 3:13 ` [PATCH 2/2] ASOC: rockchip: Use helper function devm_clk_get_enabled() Pei Xiao
2025-06-04 3:13 ` Pei Xiao
2025-06-04 17:42 ` Nicolas Frattaroli
2025-06-04 17:42 ` Nicolas Frattaroli
2025-06-05 2:00 ` Pei Xiao
2025-06-05 2:00 ` Pei Xiao
2025-06-06 3:27 ` Pei Xiao
2025-06-06 3:27 ` Pei Xiao
2025-06-06 8:26 ` Nicolas Frattaroli [this message]
2025-06-06 8:26 ` Nicolas Frattaroli
2025-06-04 17:48 ` [PATCH 0/2] Cleanup in rockchip_sai.c Nicolas Frattaroli
2025-06-04 17:48 ` Nicolas Frattaroli
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=2895073.PYKUYFuaPT@workhorse \
--to=nicolas.frattaroli@collabora.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=linux-sound@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.