From patchwork Mon Nov 6 02:30:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 10042531 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 38EBF601EB for ; Mon, 6 Nov 2017 02:31:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46E1A28D7A for ; Mon, 6 Nov 2017 02:31:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3BC0B28EF9; Mon, 6 Nov 2017 02:31:30 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 BD9CA28D7A for ; Mon, 6 Nov 2017 02:31:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751715AbdKFCb1 (ORCPT ); Sun, 5 Nov 2017 21:31:27 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:45643 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751540AbdKFCbZ (ORCPT ); Sun, 5 Nov 2017 21:31:25 -0500 Received: by mail-pg0-f65.google.com with SMTP id b192so7069258pga.2; Sun, 05 Nov 2017 18:31:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kjqR2gYgcPgmTgGc07lZrBY8J5BV37/z9H2DzSJX/Ok=; b=Z3oYZ7iteaFk79qUjA2MgnD3/XAmui3brJI02ZdeOW9RxFMefuYeLIIbykxww/D4SR 4sHRUVbmTnkK7yLOP0/RQViI2qopmogYLO/LK5GzpQ6rhxs5b1azE+FJf2DsVJI1a9lm 2j2BwiXTJyb8Ld1y6q94RvjQOjW2luY2RisOn7Zz+M8iqzQt3BhpVnH/acH7kLuAPC+T +jXHl4gdNUnbvPG6iKqKRQiiCUA4tqFAU8ku62a7Q78lojoVwsbZNgyaf1Q9t1aJvL3G kZ61wKt4fkkvf4uS4B6bD8rMevIQ4XyO7XqGWm+EIpAH7Lg0VVdHAwLLKbZPVcTUsxQ8 jzGg== 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:in-reply-to :references; bh=kjqR2gYgcPgmTgGc07lZrBY8J5BV37/z9H2DzSJX/Ok=; b=VMqtoo/wrPcGxs7EReAWQOiBSlZgNjUbidfxPWRg4t4b7TSYzYTf13NL6SkiCwnLUA mYrDz/sK0csICqUSbLOgyYtBb4PO2+sEY0cVOdB2RrGP4dQYOGe/a+PMCE46k6iSKYoU hSZEPW+/eW26fLIDzG5P1+b4Az8pV6lr7fed5zpQjoofYaQnESy/XzRuJ9TRyGhwTL44 xDUI4bsrs+vkjhQ5h6RymWX2hJncPo0rtAVYIX5I1BnIaF8D9BHMu0M3maPTgZsDY5PD h2LEu0SZrGW+B47wys4qgsLHQD1rzX8U508PH1PwzjHCE5oGPkMxoz7syEBVn74TAPJl yP2w== X-Gm-Message-State: AMCzsaWnSUwCECqnRHTJoIKkXob3im5cM36VxNZHa6ZLfFMEhWmS9XVt ZPkx35nt/BJfWwAIdlVsCs3CAe1d X-Google-Smtp-Source: ABhQp+Rbk1KZX5bHhSUfClG+VpPc8FwzKm+5o8+s8x6GwNr1iyuDDdq7g6G4QTHTM/cm0IE8yx/1Rg== X-Received: by 10.159.218.144 with SMTP id w16mr13073442plp.443.1509935484218; Sun, 05 Nov 2017 18:31:24 -0800 (PST) Received: from zzz.hsd1.wa.comcast.net (c-67-185-97-198.hsd1.wa.comcast.net. [67.185.97.198]) by smtp.gmail.com with ESMTPSA id e71sm23012520pfk.55.2017.11.05.18.31.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 05 Nov 2017 18:31:23 -0800 (PST) From: Eric Biggers To: linux-crypto@vger.kernel.org, Herbert Xu Cc: Giovanni Cabiddu , Salvatore Benedetto , Tudor-Dan Ambarus , Mat Martineau , Stephan Mueller , qat-linux@intel.com, keyrings@vger.kernel.org, Eric Biggers Subject: [PATCH v2 4/5] crypto: qat - Clean up error handling in qat_dh_set_secret() Date: Sun, 5 Nov 2017 18:30:47 -0800 Message-Id: <20171106023048.8067-5-ebiggers3@gmail.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171106023048.8067-1-ebiggers3@gmail.com> References: <20171106023048.8067-1-ebiggers3@gmail.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Biggers Update the error handling in qat_dh_set_secret() to mirror dh_set_secret(). The new version is less error-prone because freeing memory and setting the pointers to NULL is now only done in one place. Signed-off-by: Eric Biggers --- drivers/crypto/qat/qat_common/qat_asym_algs.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/crypto/qat/qat_common/qat_asym_algs.c b/drivers/crypto/qat/qat_common/qat_asym_algs.c index 6f5dd68449c6..7655fdb499de 100644 --- a/drivers/crypto/qat/qat_common/qat_asym_algs.c +++ b/drivers/crypto/qat/qat_common/qat_asym_algs.c @@ -462,11 +462,8 @@ static int qat_dh_set_params(struct qat_dh_ctx *ctx, struct dh *params) } ctx->g = dma_zalloc_coherent(dev, ctx->p_size, &ctx->dma_g, GFP_KERNEL); - if (!ctx->g) { - dma_free_coherent(dev, ctx->p_size, ctx->p, ctx->dma_p); - ctx->p = NULL; + if (!ctx->g) return -ENOMEM; - } memcpy(ctx->g + (ctx->p_size - params->g_size), params->g, params->g_size); @@ -507,18 +504,22 @@ static int qat_dh_set_secret(struct crypto_kpp *tfm, const void *buf, ret = qat_dh_set_params(ctx, ¶ms); if (ret < 0) - return ret; + goto err_clear_ctx; ctx->xa = dma_zalloc_coherent(dev, ctx->p_size, &ctx->dma_xa, GFP_KERNEL); if (!ctx->xa) { - qat_dh_clear_ctx(dev, ctx); - return -ENOMEM; + ret = -ENOMEM; + goto err_clear_ctx; } memcpy(ctx->xa + (ctx->p_size - params.key_size), params.key, params.key_size); return 0; + +err_clear_ctx: + qat_dh_clear_ctx(dev, ctx); + return ret; } static unsigned int qat_dh_max_size(struct crypto_kpp *tfm)