From patchwork Fri Aug 21 16:51:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabio Estevam X-Patchwork-Id: 7052731 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3407EC05AC for ; Fri, 21 Aug 2015 16:52:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4C6A1203B1 for ; Fri, 21 Aug 2015 16:52:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3B69020259 for ; Fri, 21 Aug 2015 16:52:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752044AbbHUQwY (ORCPT ); Fri, 21 Aug 2015 12:52:24 -0400 Received: from mail-yk0-f173.google.com ([209.85.160.173]:36201 "EHLO mail-yk0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751699AbbHUQwY (ORCPT ); Fri, 21 Aug 2015 12:52:24 -0400 Received: by ykfw73 with SMTP id w73so76260160ykf.3 for ; Fri, 21 Aug 2015 09:52:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=y4OBv099Lpr0tadqd0wTe2XLXENdzkIzn0VGs+73cCI=; b=GpspHUzBKsGfxTVs9+LCHunSiVYCwhxclrDVgWv0WHNlfoh82OhrABHdkD9C99P7cv Yv+QsgdtUrBsreyr1N6bmXHp2fugqSI8c8G2SJ0I/2NdBqy6+RHmUoX727ygLkS8tbxL xLvFetV93lD6/PvmC3nvhH8voWTDKFIUB7RkTtXExVu7I0WkSQ0k5ubI/R8q+wMv7xfN eFjndyd9pD03Jpza7FKF56o006VgyRfUEy0wEpo9IZf2FSnCzWvMDKp617NVTslCqiam ZZMqVwqcw7hzwNEQRQhDNO7ZxFbX4UGAbdTI1kaleKVlmF3LwLBkeZDndA5lKpM3o3xQ VjHw== X-Received: by 10.170.43.208 with SMTP id 199mr13016595ykl.124.1440175943419; Fri, 21 Aug 2015 09:52:23 -0700 (PDT) Received: from localhost.localdomain ([187.64.230.54]) by smtp.gmail.com with ESMTPSA id w129sm7905193ywd.47.2015.08.21.09.52.21 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 21 Aug 2015 09:52:22 -0700 (PDT) From: Fabio Estevam To: herbert@gondor.apana.org.au Cc: vicki.milhoan@freescale.com, horia.geanta@freescale.com, linux-crypto@vger.kernel.org, Fabio Estevam Subject: [PATCH v3 1/3] crypto: caam: ctrl: Fix the error handling Date: Fri, 21 Aug 2015 13:51:58 -0300 Message-Id: <1440175920-30884-1-git-send-email-festevam@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Fabio Estevam In the error path we should disable the resources that were previously acquired, so fix the error handling accordingly. Signed-off-by: Fabio Estevam Reviewed-by: Horia Geant? --- Changes since v2: - Add a missing "ret = -ENOMEM" drivers/crypto/caam/ctrl.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c index 81b552d..cd22849 100644 --- a/drivers/crypto/caam/ctrl.c +++ b/drivers/crypto/caam/ctrl.c @@ -474,27 +474,27 @@ static int caam_probe(struct platform_device *pdev) ret = clk_prepare_enable(ctrlpriv->caam_ipg); if (ret < 0) { dev_err(&pdev->dev, "can't enable CAAM ipg clock: %d\n", ret); - return -ENODEV; + return ret; } ret = clk_prepare_enable(ctrlpriv->caam_mem); if (ret < 0) { dev_err(&pdev->dev, "can't enable CAAM secure mem clock: %d\n", ret); - return -ENODEV; + goto disable_caam_ipg; } ret = clk_prepare_enable(ctrlpriv->caam_aclk); if (ret < 0) { dev_err(&pdev->dev, "can't enable CAAM aclk clock: %d\n", ret); - return -ENODEV; + goto disable_caam_mem; } ret = clk_prepare_enable(ctrlpriv->caam_emi_slow); if (ret < 0) { dev_err(&pdev->dev, "can't enable CAAM emi slow clock: %d\n", ret); - return -ENODEV; + goto disable_caam_aclk; } /* Get configuration properties from device tree */ @@ -502,7 +502,8 @@ static int caam_probe(struct platform_device *pdev) ctrl = of_iomap(nprop, 0); if (ctrl == NULL) { dev_err(dev, "caam: of_iomap() failed\n"); - return -ENOMEM; + ret = -ENOMEM; + goto disable_caam_emi_slow; } /* Finding the page size for using the CTPR_MS register */ comp_params = rd_reg32(&ctrl->perfmon.comp_parms_ms); @@ -586,8 +587,8 @@ static int caam_probe(struct platform_device *pdev) sizeof(struct platform_device *) * rspec, GFP_KERNEL); if (ctrlpriv->jrpdev == NULL) { - iounmap(ctrl); - return -ENOMEM; + ret = -ENOMEM; + goto iounmap_ctrl; } ring = 0; @@ -627,8 +628,8 @@ static int caam_probe(struct platform_device *pdev) /* If no QI and no rings specified, quit and go home */ if ((!ctrlpriv->qi_present) && (!ctrlpriv->total_jobrs)) { dev_err(dev, "no queues configured, terminating\n"); - caam_remove(pdev); - return -ENOMEM; + ret = -ENOMEM; + goto caam_remove; } cha_vid_ls = rd_reg32(&ctrl->perfmon.cha_id_ls); @@ -685,8 +686,7 @@ static int caam_probe(struct platform_device *pdev) } while ((ret == -EAGAIN) && (ent_delay < RTSDCTL_ENT_DLY_MAX)); if (ret) { dev_err(dev, "failed to instantiate RNG"); - caam_remove(pdev); - return ret; + goto caam_remove; } /* * Set handles init'ed by this module as the complement of the @@ -790,6 +790,20 @@ static int caam_probe(struct platform_device *pdev) &ctrlpriv->ctl_tdsk_wrap); #endif return 0; + +caam_remove: + caam_remove(pdev); +iounmap_ctrl: + iounmap(ctrl); +disable_caam_emi_slow: + clk_disable_unprepare(ctrlpriv->caam_emi_slow); +disable_caam_aclk: + clk_disable_unprepare(ctrlpriv->caam_aclk); +disable_caam_mem: + clk_disable_unprepare(ctrlpriv->caam_mem); +disable_caam_ipg: + clk_disable_unprepare(ctrlpriv->caam_ipg); + return ret; } static struct of_device_id caam_match[] = {