From patchwork Fri Apr 28 20:00:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabio Estevam X-Patchwork-Id: 9705283 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 673C260225 for ; Fri, 28 Apr 2017 20:00:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5845D2862A for ; Fri, 28 Apr 2017 20:00:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B63D28698; Fri, 28 Apr 2017 20:00:27 +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 D21AB2862A for ; Fri, 28 Apr 2017 20:00:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S642276AbdD1UA0 (ORCPT ); Fri, 28 Apr 2017 16:00:26 -0400 Received: from mail-qk0-f195.google.com ([209.85.220.195]:32797 "EHLO mail-qk0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S642167AbdD1UAY (ORCPT ); Fri, 28 Apr 2017 16:00:24 -0400 Received: by mail-qk0-f195.google.com with SMTP id o85so10344265qkh.0 for ; Fri, 28 Apr 2017 13:00:24 -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=VI7xvhShpkPuvwITBUnA+Qf+cDRJ0oPQiSDhjZm92tnDpVA2k6O28I9STqmleG5HKB pDcMtckx+QAHUgpEk0uBwROZUmqfS3p3H8pzft755cHlv2ykJ6qu008SOmsAbXwsJNS7 NnNzf4gKDnp8TAGHz+3vvgDidiSkyB3sKJzNSPTFoMuu1d4cMN5A6Qp+/a8qXinTjj/H tkoguhi8Bsh5IKUsI0VNJasmnAnD7lrvMZwWrrr2c0xJrDb2NR1fhlu1xEvDCtCshsyc OkYed858CeqdxbGVSLEqFM+ACDlRDFp78S6hsrfyi467I52TRJExLY2mEsA/7PDBPY1P T0Ww== 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=aV5Xcj58h+A/VNnTD7uUOUG/yXFV3XB8tVGVwEYmbi3W6MdJE6IocpCVzUYny4kB3Z y3L/aYLu2Kir5zQeerEoQakVBWaW7/1E1xi9oP1G7/vE62UjjDWNLJLOCVl2aPLoQ/sx BggT5KgtWzv3d6bdGH7MV/HBPIj3IFb2qEirYjmPg+5Yikau2UI2wU2OXUrTdQm/jzCO r4a4GDqAXXlwuVD+wqIOQJU4Lv+7nZ73hd+/9gVCeZKbWTgXfJql5Ec7DudeBBDXHnka 5ijoOiz8v6NNMA3mppdFKE6P3jXEBEqJKZRFk+Bmj9lOPlk14IEPutFZkoIVGthCLVMh GkVg== X-Gm-Message-State: AN3rC/78qRy10QmCs3MTAVy8g6qw9hKRCqEIxqAaicV9o36+hpWZEynt X39bSHLF906GNA== X-Received: by 10.55.68.84 with SMTP id r81mr8806284qka.250.1493409623852; Fri, 28 Apr 2017 13:00:23 -0700 (PDT) Received: from localhost.localdomain ([187.180.184.103]) by smtp.gmail.com with ESMTPSA id f203sm4525757qka.11.2017.04.28.13.00.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 28 Apr 2017 13:00:23 -0700 (PDT) From: Fabio Estevam To: ulf.hansson@linaro.org Cc: adrian.hunter@intel.com, dongas86@gmail.com, linux-mmc@vger.kernel.org, Fabio Estevam Subject: [PATCH] mmc: sdhci-esdhc-imx: Check the return value from clk_prepare_enable() Date: Fri, 28 Apr 2017 17:00:04 -0300 Message-Id: <1493409604-24716-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