[PATCH] mmc: sdhci-of-at91: handle clock enable failures in set_clks_presets()
Ulf Hansson
ulf.hansson at oss.qualcomm.com
Mon Nov 30 08:15:32 PST 2026
On Tue, Nov 17, 2026 at 3:04 AM Luo Yifan <luoyifan at cmss.chinamobile.com> wrote:
>
> sdhci_at91_set_clks_presets() enables hclock, mainck and gck but ignores
> the return value of all three clk_prepare_enable() calls. It returns 0
> even when a clock could not be enabled.
>
> The function is called from the probe path and from the system resume
> path. In both cases the caller continues to use the controller even
> though the clocks may be off: probe proceeds to sdhci_get_of_property()
> and sdhci_add_host(), and sdhci_at91_runtime_resume() calls
> sdhci_runtime_resume_host(), which accesses the controller registers.
> Accessing the controller without its clocks can hang the bus.
>
> Check the return value of each clk_prepare_enable() and unwind the clocks
> enabled so far when one fails. hclock is enabled first and is needed for
> the register accesses inside the function, so it has to be checked as
> well.
>
> Signed-off-by: Luo Yifan <luoyifan at cmss.chinamobile.com>
Applied for next, thanks!
Kind regards
Uffe
> ---
> drivers/mmc/host/sdhci-of-at91.c | 21 ++++++++++++++++++---
> 1 file changed, 18 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mmc/host/sdhci-of-at91.c b/drivers/mmc/host/sdhci-of-at91.c
> index 7c4ac65f24..8acf2ddf58 100644
> --- a/drivers/mmc/host/sdhci-of-at91.c
> +++ b/drivers/mmc/host/sdhci-of-at91.c
> @@ -173,8 +173,12 @@ static int sdhci_at91_set_clks_presets(struct device *dev)
> unsigned int clk_base, clk_mul;
> unsigned int gck_rate, clk_base_rate;
> unsigned int preset_div;
> + int ret;
> +
> + ret = clk_prepare_enable(priv->hclock);
> + if (ret)
> + return ret;
>
> - clk_prepare_enable(priv->hclock);
> caps0 = readl(host->ioaddr + SDHCI_CAPABILITIES);
> caps1 = readl(host->ioaddr + SDHCI_CAPABILITIES_1);
>
> @@ -223,10 +227,21 @@ static int sdhci_at91_set_clks_presets(struct device *dev)
> writew(SDHCI_AT91_PRESET_COMMON_CONF | preset_div,
> host->ioaddr + SDHCI_PRESET_FOR_DDR50);
>
> - clk_prepare_enable(priv->mainck);
> - clk_prepare_enable(priv->gck);
> + ret = clk_prepare_enable(priv->mainck);
> + if (ret)
> + goto err_hclock;
> +
> + ret = clk_prepare_enable(priv->gck);
> + if (ret)
> + goto err_mainck;
>
> return 0;
> +
> +err_mainck:
> + clk_disable_unprepare(priv->mainck);
> +err_hclock:
> + clk_disable_unprepare(priv->hclock);
> + return ret;
> }
>
> static int sdhci_at91_suspend(struct device *dev)
> --
> 2.24.4
>
>
>
More information about the linux-arm-kernel
mailing list