From patchwork Sun Jun 21 09:07:46 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: 191280 Delivered-To: patch@linaro.org Received: by 2002:a92:1f07:0:0:0:0:0 with SMTP id i7csp77336ile; Sun, 21 Jun 2020 02:08:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxa7NhXwgVfH79f92xYg1uuKJcw64pQ7aG1PAk+OsqCUCdYLbb9+VofOmTWt2iacgWy8Djp X-Received: by 2002:aa7:d2d2:: with SMTP id k18mr4519801edr.16.1592730487847; Sun, 21 Jun 2020 02:08:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592730487; cv=none; d=google.com; s=arc-20160816; b=0o5SY8OE77Cay1vKmGuP4Bq3EMVJOMEVZ2RCogb/FL/TDUzlsQ1HYJh8sjSvAQkAGD yvi1Kljw+YflNGFrAHFNNuIa9TKieTU2oFCToaR1ZHMxuNs/LSVS5GvlR3HbcqYDtr4x 7TeLJP3i+24ZehU5iMQnnY5hRoOj1IgpgwGBMFcfRN+4oBzQMl56FS6y67sNO8gQoWaL 3zwcXp4CT8He9fOHfQp1M3YbO7vQH3IwJ05RfJQq9VxphpAxXjzMuuUhBQ3iN5Z+MQOA zd3qkil5oKz55SCCyV9WdURK1kjAITqSOEs1Yy+RyfJ+/HEPmMl/oChELS0EviHc4ydL Crhw== 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=EGWDaCVhn53g8GmCykP3RBREtYK+t6KhjmF4l60MzCM=; b=WowhyBycwSKXKQDiK7bIzu1EFLPg8PpGlsEczj1S05+W/AotJiJoFl3PwKu68RdUMl YXB/m8GB82c+5i7/osYJFL4Mb4yjFnohdj4eCP4QtapK0kQMixS2vwEsB5Z4yhKrlA7L E/sYNfSHGgJJEdiQ1JtFgtByZcMHZKV6+7vp+b8KqYrR7Mbe+wJyzLu+qDAiuZ0ShqId 2B7CN0aVq9TafNrZZDs40S6zUzewF+9qFl0xJXWvMd1A696WZs+meoPZFLAK7n6mL/08 D3MvFildMpBy+d2zGc4+e11qv1gn1LITisUekAACNk43EuosrNs003Ar21EbyuKqJ4mv dnXw== 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 y16si7050120ejb.177.2020.06.21.02.08.07; Sun, 21 Jun 2020 02:08:07 -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 S1729618AbgFUJH7 (ORCPT + 1 other); Sun, 21 Jun 2020 05:07:59 -0400 Received: from foss.arm.com ([217.140.110.172]:47886 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727119AbgFUJH6 (ORCPT ); Sun, 21 Jun 2020 05:07:58 -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 2B43BD6E; Sun, 21 Jun 2020 02:07:58 -0700 (PDT) Received: from e110176-lin.arm.com (E113494.Arm.com [10.50.66.186]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C7C203F6CF; Sun, 21 Jun 2020 02:07:56 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" Cc: Ofir Drang , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] crypto: ccree: fix resource leak on error path Date: Sun, 21 Jun 2020 12:07:46 +0300 Message-Id: <20200621090748.18464-2-gilad@benyossef.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200621090748.18464-1-gilad@benyossef.com> References: <20200621090748.18464-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 --- 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..e61f35ca9945 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 out_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 out_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; +out_key: + kfree(ctx_p->user.key); +out_shash: + crypto_free_shash(ctx_p->shash_tfm); + + return -ENOMEM; } static void cc_cipher_exit(struct crypto_tfm *tfm)