[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <2531d1ef-2450-4479-b32e-b9c861ffadd1@rock-chips.com>
Date: Fri, 23 Jan 2026 14:48:14 +0800
From: Shawn Lin <shawn.lin@...k-chips.com>
To: "ping.gao" <ping.gao@...sung.com>
Cc: shawn.lin@...k-chips.com, jh80.chung@...sung.com,
sebastian.reichel@...labora.com, linux-mmc@...r.kernel.org,
ulf.hansson@...aro.org, linux-kernel@...r.kernel.org, hy50.seo@...sung.com,
kwangwon.min@...sung.com
Subject: Re: [PATCH] drivers: mmc: Replace manual
devm_clk_get/clk_prepare_enable with devm_clk_get_optional_enabled
在 2026/01/23 星期五 13:45, ping.gao 写道:
> By using , we:
> - Automatically handle optional clocks (return NULL if not present).
> - Ensure the clock is enabled upon acquisition.
> This change reduces code complexity and improves reliability.
>
The commit tile should be:
mmc: dw_mmc: Replace....
> before biu_clk in dwmmc driver devm_clk_get fail, but it's ERR_PTR,
> not null,it will panic when call clk_prepare
> log is below:
----8<----
>
> diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
> index 61f6986f15ef..18981d010b62 100644
> --- a/drivers/mmc/host/dw_mmc.c
> +++ b/drivers/mmc/host/dw_mmc.c
> @@ -3375,20 +3375,10 @@ int dw_mci_probe(struct dw_mci *host)
> "platform data not available\n");
> }
>
> - host->biu_clk = devm_clk_get(host->dev, "biu");
> - if (IS_ERR(host->biu_clk)) {
> - dev_dbg(host->dev, "biu clock not available\n");
> - ret = PTR_ERR(host->biu_clk);
> - if (ret == -EPROBE_DEFER)
> - return ret;
> -
> - } else {
> - ret = clk_prepare_enable(host->biu_clk);
> - if (ret) {
> - dev_err(host->dev, "failed to enable biu clock\n");
> - return ret;
> - }
> - }
> + host->biu_clk = devm_clk_get_optional_enabled(host->dev, "biu");
This won't work, as biu_clk will automatically be disabled, unprepared
and freed when dwmmc host is unbound from the bus. Given we need to
control biu_clk in runtime, you could just use devm_clk_get_optional,
it will return NULL which serves as a dummy clk, if biu isn't present.
Then clk_prepare_enable/clk_disable_unprepare for biu_clk is safe to
bail out internally.
> + ret = PTR_ERR_OR_ZERO(host->biu_clk);
> + if (ret)
> + return dev_err_probe(host->dev, ret, "failed to get biu clock\n");
>
> host->ciu_clk = devm_clk_get(host->dev, "ciu");
> if (IS_ERR(host->ciu_clk)) {
Powered by blists - more mailing lists