From patchwork Sun Jun 21 11:19:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Ben-Yossef X-Patchwork-Id: 191284 Delivered-To: patch@linaro.org Received: by 2002:a92:1f07:0:0:0:0:0 with SMTP id i7csp147067ile; Sun, 21 Jun 2020 04:20:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdX32L8vMT17F505tT2XogB3jUrYc6qYHklZSbgad8v0w+N/oDZ9ObDbCMRQdcE5fTkBOg X-Received: by 2002:a17:906:8392:: with SMTP id p18mr1704000ejx.24.1592738414507; Sun, 21 Jun 2020 04:20:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592738414; cv=none; d=google.com; s=arc-20160816; b=WTgBFN7zJkqO4kWi+0plN2YE0tCE7CjTiaWzOUyHzvodApLcq67dqmAigdladyCNna 4Uug2UiH4J2fQi0ALPM1AZEgCQnhTiROKuAUX4iZPqIRxbtKvKp1TNx3H2Q9FC39vRhj NHok3TN9g3g8AQRpDgFfI00hMzZX3wcffMidIH6adg2bkPbUDBQPeYcC/neHTG1hYVN1 gQALDYVHFwsBv/WgEnxr389PYerWmKgQ1OAnVOadqpxTSjk1uJk4ngES3pGk/HxA65Ip OzDgGBZ6iI6LYQZ2RMM4xqniUiAc+b/4O29SrwPwZG1zhDVC2teJe89DxOKP3yT1DfhJ GPNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=XItUOgtDkSC8N2WME8ORXj4VI644vnWrjLBjNfSJsjY=; b=tki4npEv5Ju3JfJNNbuACcyEVS6z1Ad5SYFDcVRClF6G23FPseLM2CXyUBbx/2bHbR do+w1igUEuH5JC5DpFs+7sQKFvVHMAz7oErbkE/HHRMV+9qQAJWW1IqUnP1Cj1KRp5eS OXk0+8pdHYw7QzEI2Pv5A7JfBjOKMuUI1BN12yM4jriPQaQhg5GgrQ8GzyLOaXxlk9x8 lN1tAKRX4mBuTFVfDKISLySqyTknxGO2hT+fbluP2qzdK9IK/J8z3XsPYmI2jN1I83Ey eq0OE/dAGAU14NlWinR+8aQ8oDj+pZfqFoRj4jIehWuN3+mhTlw9pIXMki0E3FNVKkKb QERg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r4si3057385edl.262.2020.06.21.04.20.14; Sun, 21 Jun 2020 04:20:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729975AbgFULUK (ORCPT + 1 other); Sun, 21 Jun 2020 07:20:10 -0400 Received: from foss.arm.com ([217.140.110.172]:58554 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729878AbgFULUK (ORCPT ); Sun, 21 Jun 2020 07:20:10 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 47D3A101E; Sun, 21 Jun 2020 04:20:09 -0700 (PDT) Received: from e110176-lin.arm.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DFEA03F6CF; Sun, 21 Jun 2020 04:20:07 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ofir Drang , Markus Elfring , "David S. Miller" Subject: [PATCH v2 1/3] crypto: ccree: fix resource leak on error path Date: Sun, 21 Jun 2020 14:19:57 +0300 Message-Id: <20200621112000.31495-2-gilad@benyossef.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200621112000.31495-1-gilad@benyossef.com> References: <20200621112000.31495-1-gilad@benyossef.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Fix a small resource leak on the error path of cipher processing. Signed-off-by: Gilad Ben-Yossef Fixes: 63ee04c8b491e ("crypto: ccree - add skcipher support") Cc: Markus Elfring --- drivers/crypto/ccree/cc_cipher.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) -- 2.27.0 diff --git a/drivers/crypto/ccree/cc_cipher.c b/drivers/crypto/ccree/cc_cipher.c index 42ec46be427d..c2f759a04625 100644 --- a/drivers/crypto/ccree/cc_cipher.c +++ b/drivers/crypto/ccree/cc_cipher.c @@ -163,7 +163,6 @@ static int cc_cipher_init(struct crypto_tfm *tfm) skcipher_alg.base); struct device *dev = drvdata_to_dev(cc_alg->drvdata); unsigned int max_key_buf_size = cc_alg->skcipher_alg.max_keysize; - int rc = 0; dev_dbg(dev, "Initializing context @%p for %s\n", ctx_p, crypto_tfm_alg_name(tfm)); @@ -175,10 +174,19 @@ static int cc_cipher_init(struct crypto_tfm *tfm) ctx_p->flow_mode = cc_alg->flow_mode; ctx_p->drvdata = cc_alg->drvdata; + if (ctx_p->cipher_mode == DRV_CIPHER_ESSIV) { + /* Alloc hash tfm for essiv */ + ctx_p->shash_tfm = crypto_alloc_shash("sha256-generic", 0, 0); + if (IS_ERR(ctx_p->shash_tfm)) { + dev_err(dev, "Error allocating hash tfm for ESSIV.\n"); + return PTR_ERR(ctx_p->shash_tfm); + } + } + /* Allocate key buffer, cache line aligned */ ctx_p->user.key = kmalloc(max_key_buf_size, GFP_KERNEL); if (!ctx_p->user.key) - return -ENOMEM; + goto free_shash; dev_dbg(dev, "Allocated key buffer in context. key=@%p\n", ctx_p->user.key); @@ -190,21 +198,19 @@ static int cc_cipher_init(struct crypto_tfm *tfm) if (dma_mapping_error(dev, ctx_p->user.key_dma_addr)) { dev_err(dev, "Mapping Key %u B at va=%pK for DMA failed\n", max_key_buf_size, ctx_p->user.key); - return -ENOMEM; + goto free_key; } dev_dbg(dev, "Mapped key %u B at va=%pK to dma=%pad\n", max_key_buf_size, ctx_p->user.key, &ctx_p->user.key_dma_addr); - if (ctx_p->cipher_mode == DRV_CIPHER_ESSIV) { - /* Alloc hash tfm for essiv */ - ctx_p->shash_tfm = crypto_alloc_shash("sha256-generic", 0, 0); - if (IS_ERR(ctx_p->shash_tfm)) { - dev_err(dev, "Error allocating hash tfm for ESSIV.\n"); - return PTR_ERR(ctx_p->shash_tfm); - } - } + return 0; - return rc; +free_key: + kfree(ctx_p->user.key); +free_shash: + crypto_free_shash(ctx_p->shash_tfm); + + return -ENOMEM; } static void cc_cipher_exit(struct crypto_tfm *tfm)