From patchwork Tue May 16 22:08:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabio Estevam X-Patchwork-Id: 9729727 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 798E7602DB for ; Tue, 16 May 2017 22:08:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68D77288D7 for ; Tue, 16 May 2017 22:08:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 596AE2891A; Tue, 16 May 2017 22:08:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6875288D7 for ; Tue, 16 May 2017 22:08:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751630AbdEPWIp (ORCPT ); Tue, 16 May 2017 18:08:45 -0400 Received: from mail-qk0-f194.google.com ([209.85.220.194]:35204 "EHLO mail-qk0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751300AbdEPWIo (ORCPT ); Tue, 16 May 2017 18:08:44 -0400 Received: by mail-qk0-f194.google.com with SMTP id k74so24827081qke.2 for ; Tue, 16 May 2017 15:08:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=6MYO1byrkCKvTWPBhULQoQ/5RiQ0Ebfy9obuWBVgTno=; b=g8mQ7/021juHSP+E5MkR0f3yQNtT7EBjPww8pAfBRUodDDiZJDtLsuvmXJ54Vrfll7 77xOY2+AHNuL2pXujXuj50qW14pUkWK6VMV6cFN2Yy+OtPWypE6f5BrXFYF9VM7rVQTo wsmKRPbiLbG9Vc1uRtvtW8ewMM0zsH8qycaKG0HYyoU+gB40WIsHj1AIEAVWDa+sKqwa fFzGvE9EDDKlEKXBVb4SOGCV0RHD0ejmM8P8sRn1gNMOrX7ss+SiFNh6KfuOMXmNoZtM WASHKyvmU81aNZFXOuHNAiCSOH9NsBTgWJJQD4/YGQJe6ED1ou5tFiCvqkLxFuHhfxdt 7glg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=6MYO1byrkCKvTWPBhULQoQ/5RiQ0Ebfy9obuWBVgTno=; b=fjrnQAsrOOsrkSHDJdHw+k9BGFPQdMgTQZ3hSO/B9YWhGBxGERavMxHm+vjKSYBzco zkwc1mQPrXI1prYLBAziIP3ubDPJD6qMHJWWoVtXRnv0Y6nYOe5HJUQRO7/B7TxIDMhe dtnqraXO26/ewhgmGIga7I2nwTuN0b5get4nekeiYLRR163XU5xQiePrm2zJ8/+gLcEn J70ZFdQBBUDeWBUkoQN25Y/fBXkGo9DVOlF3hZHcAhSABizYezk2l9j34IIpRzCnHZ8I HdgrN4dSzf2PaW7Q/kcx0U1yxsMhi4byT41DvDLp8FsOMcNgQvU527cCNK/6DhL86iQy WF0A== X-Gm-Message-State: AODbwcDxuXKomJ8NH7AXZ1dT2SN4vQrBWgZCUDncINdloYd1+r6ByAP9 yhFsooN40qQmmw== X-Received: by 10.55.39.131 with SMTP id n125mr178933qkn.215.1494972523750; Tue, 16 May 2017 15:08:43 -0700 (PDT) Received: from localhost.localdomain ([189.61.213.245]) by smtp.gmail.com with ESMTPSA id u68sm105648qku.2.2017.05.16.15.08.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 May 2017 15:08:43 -0700 (PDT) From: Fabio Estevam To: ulf.hansson@linaro.org Cc: adrian.hunter@intel.com, aisheng.dong@nxp.com, linux-mmc@vger.kernel.org, Fabio Estevam Subject: [PATCH RESEND] mmc: sdhci-esdhc-imx: Check the return value from clk_prepare_enable() Date: Tue, 16 May 2017 19:08:31 -0300 Message-Id: <1494972511-17655-1-git-send-email-festevam@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Fabio Estevam clk_prepare_enable() may fail, so we should better check its return value and propagate it in the case of error. Signed-off-by: Fabio Estevam --- drivers/mmc/host/sdhci-esdhc-imx.c | 54 +++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c index 23d8b8a..b5c7241 100644 --- a/drivers/mmc/host/sdhci-esdhc-imx.c +++ b/drivers/mmc/host/sdhci-esdhc-imx.c @@ -1250,14 +1250,20 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev) pltfm_host->clk = imx_data->clk_per; pltfm_host->clock = clk_get_rate(pltfm_host->clk); - clk_prepare_enable(imx_data->clk_per); - clk_prepare_enable(imx_data->clk_ipg); - clk_prepare_enable(imx_data->clk_ahb); + err = clk_prepare_enable(imx_data->clk_per); + if (err) + goto free_sdhci; + err = clk_prepare_enable(imx_data->clk_ipg); + if (err) + goto disable_per_clk; + err = clk_prepare_enable(imx_data->clk_ahb); + if (err) + goto disable_ipg_clk; imx_data->pinctrl = devm_pinctrl_get(&pdev->dev); if (IS_ERR(imx_data->pinctrl)) { err = PTR_ERR(imx_data->pinctrl); - goto disable_clk; + goto disable_ahb_clk; } imx_data->pins_default = pinctrl_lookup_state(imx_data->pinctrl, @@ -1297,13 +1303,13 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev) else err = sdhci_esdhc_imx_probe_nondt(pdev, host, imx_data); if (err) - goto disable_clk; + goto disable_ahb_clk; sdhci_esdhc_imx_hwinit(host); err = sdhci_add_host(host); if (err) - goto disable_clk; + goto disable_ahb_clk; pm_runtime_set_active(&pdev->dev); pm_runtime_set_autosuspend_delay(&pdev->dev, 50); @@ -1313,10 +1319,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev) return 0; -disable_clk: - clk_disable_unprepare(imx_data->clk_per); - clk_disable_unprepare(imx_data->clk_ipg); +disable_ahb_clk: clk_disable_unprepare(imx_data->clk_ahb); +disable_ipg_clk: + clk_disable_unprepare(imx_data->clk_ipg); +disable_per_clk: + clk_disable_unprepare(imx_data->clk_per); free_sdhci: sdhci_pltfm_free(pdev); return err; @@ -1393,14 +1401,34 @@ static int sdhci_esdhc_runtime_resume(struct device *dev) struct sdhci_host *host = dev_get_drvdata(dev); struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); struct pltfm_imx_data *imx_data = sdhci_pltfm_priv(pltfm_host); + int err; if (!sdhci_sdio_irq_enabled(host)) { - clk_prepare_enable(imx_data->clk_per); - clk_prepare_enable(imx_data->clk_ipg); + err = clk_prepare_enable(imx_data->clk_per); + if (err) + return err; + err = clk_prepare_enable(imx_data->clk_ipg); + if (err) + goto disable_per_clk; } - clk_prepare_enable(imx_data->clk_ahb); + err = clk_prepare_enable(imx_data->clk_ahb); + if (err) + goto disable_ipg_clk; + err = sdhci_runtime_resume_host(host); + if (err) + goto disable_ahb_clk; + + return 0; - return sdhci_runtime_resume_host(host); +disable_ahb_clk: + clk_disable_unprepare(imx_data->clk_ahb); +disable_ipg_clk: + if (!sdhci_sdio_irq_enabled(host)) + clk_disable_unprepare(imx_data->clk_ipg); +disable_per_clk: + if (!sdhci_sdio_irq_enabled(host)) + clk_disable_unprepare(imx_data->clk_per); + return err; } #endif