Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4409219imu; Mon, 7 Jan 2019 22:59:24 -0800 (PST) X-Google-Smtp-Source: ALg8bN6ALc2J+zViuq88KI+LVbY+XKGIUILAmgIj4v+bnf76LtXzxGpHZFGYO2okh4bCPIvsaTB0 X-Received: by 2002:a63:e74b:: with SMTP id j11mr495519pgk.397.1546930764005; Mon, 07 Jan 2019 22:59:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546930763; cv=none; d=google.com; s=arc-20160816; b=SXGH7LnFCwVVpUV17GpLFXSOmetuZagFaZ9HVyP+ucdzZwpIsc9w1kbURvtiK5MwvS qNS/R026nBcUFXwtjEZqSFNLSxFQJD0x3dInV3QqejBg+Qh7nRwukwOkAEMVMMY2+Ad5 v3dDbnmb0bDH1Fm4DQTX1Wl0qw4a/Py7odoQZJeSw7JF+gIzEHu3DUfy4+hrF0vVWDhC cCPTPUU9kY4IfEdOAULJjh9vZm36zuzX3lpSuZGRNd+vmCGzwx1Ekr7YnihODt4vRqPY +VCBkchk1rX6PFXMcJGuUimVE/0ss+dWyTTupsXrYPmv/OcVi9QFJKKOy0QATIMMvwGl dFuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:message-id; bh=QffH7ulbBIRuVv6IbhwzVvX4EK28JfSXiwvDbs0Pl+w=; b=AxNfLiJc0WLUl9w4yJu8sNb4agQWlItBlb6pOTvjOgAMH2ajQbdxCD0+Gv37HmwqtW ycTHeDlFUl7gxjmlEX0tk4y5oavqkL8c/1dmxOjlRCAPMT7/3LjSv3pSt6SftpAaQUsq nwE8dG7HnwchY169EfowsKlnX9XqjwPE4ZDM+x2khH8Uh0apYG2+5/hJ8R1SLdCHHWTn sP2Uqcg3QhG8cRRmNustG0WklA9Iy7NzJPIhwC2if7QnVXshPIyvRsKt8t30dI5Hr+a7 VAh+ktq0zB60dyljNC2MGwZc2+V1czu/M8Lui6HqFxtQcLe3RxqwySPifR6OFWXNS11Q u3gw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c21si13068371plo.165.2019.01.07.22.59.08; Mon, 07 Jan 2019 22:59:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727794AbfAHG4t (ORCPT + 99 others); Tue, 8 Jan 2019 01:56:49 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:41849 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727435AbfAHG4t (ORCPT ); Tue, 8 Jan 2019 01:56:49 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 43YjjV1GqLz9v2g7; Tue, 8 Jan 2019 07:56:46 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id UPAcuR7dcLCv; Tue, 8 Jan 2019 07:56:46 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 43YjjV0l5YzB09Zh; Tue, 8 Jan 2019 07:56:46 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id ECD0B8B791; Tue, 8 Jan 2019 07:56:46 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id PXTZ2k2jivoZ; Tue, 8 Jan 2019 07:56:46 +0100 (CET) Received: from PO15451.localdomain (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id BD8558B754; Tue, 8 Jan 2019 07:56:46 +0100 (CET) Received: by localhost.localdomain (Postfix, from userid 0) id 7CCEB717D8; Tue, 8 Jan 2019 06:56:46 +0000 (UTC) Message-Id: <5ed91db5e2976a4c260465c3d027acc9affd2d2b.1545445924.git.christophe.leroy@c-s.fr> From: Christophe Leroy Subject: [PATCH v4 1/2] crypto: talitos - reorder code in talitos_edesc_alloc() To: Herbert Xu , "David S. Miller" , Horia Geanta Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, stable@vger.kernel.org Date: Tue, 8 Jan 2019 06:56:46 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch moves the mapping of IV after the kmalloc(). This avoids having to unmap in case kmalloc() fails. Signed-off-by: Christophe Leroy --- new in v4 drivers/crypto/talitos.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index 45e20707cef8..54d80e7edb86 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c @@ -1361,23 +1361,18 @@ static struct talitos_edesc *talitos_edesc_alloc(struct device *dev, struct talitos_private *priv = dev_get_drvdata(dev); bool is_sec1 = has_ftr_sec1(priv); int max_len = is_sec1 ? TALITOS1_MAX_DATA_LEN : TALITOS2_MAX_DATA_LEN; - void *err; if (cryptlen + authsize > max_len) { dev_err(dev, "length exceeds h/w max limit\n"); return ERR_PTR(-EINVAL); } - if (ivsize) - iv_dma = dma_map_single(dev, iv, ivsize, DMA_TO_DEVICE); - if (!dst || dst == src) { src_len = assoclen + cryptlen + authsize; src_nents = sg_nents_for_len(src, src_len); if (src_nents < 0) { dev_err(dev, "Invalid number of src SG.\n"); - err = ERR_PTR(-EINVAL); - goto error_sg; + return ERR_PTR(-EINVAL); } src_nents = (src_nents == 1) ? 0 : src_nents; dst_nents = dst ? src_nents : 0; @@ -1387,16 +1382,14 @@ static struct talitos_edesc *talitos_edesc_alloc(struct device *dev, src_nents = sg_nents_for_len(src, src_len); if (src_nents < 0) { dev_err(dev, "Invalid number of src SG.\n"); - err = ERR_PTR(-EINVAL); - goto error_sg; + return ERR_PTR(-EINVAL); } src_nents = (src_nents == 1) ? 0 : src_nents; dst_len = assoclen + cryptlen + (encrypt ? authsize : 0); dst_nents = sg_nents_for_len(dst, dst_len); if (dst_nents < 0) { dev_err(dev, "Invalid number of dst SG.\n"); - err = ERR_PTR(-EINVAL); - goto error_sg; + return ERR_PTR(-EINVAL); } dst_nents = (dst_nents == 1) ? 0 : dst_nents; } @@ -1425,10 +1418,10 @@ static struct talitos_edesc *talitos_edesc_alloc(struct device *dev, alloc_len += sizeof(struct talitos_desc); edesc = kmalloc(alloc_len, GFP_DMA | flags); - if (!edesc) { - err = ERR_PTR(-ENOMEM); - goto error_sg; - } + if (!edesc) + return ERR_PTR(-ENOMEM); + if (ivsize) + iv_dma = dma_map_single(dev, iv, ivsize, DMA_TO_DEVICE); memset(&edesc->desc, 0, sizeof(edesc->desc)); edesc->src_nents = src_nents; @@ -1445,10 +1438,6 @@ static struct talitos_edesc *talitos_edesc_alloc(struct device *dev, DMA_BIDIRECTIONAL); } return edesc; -error_sg: - if (iv_dma) - dma_unmap_single(dev, iv_dma, ivsize, DMA_TO_DEVICE); - return err; } static struct talitos_edesc *aead_edesc_alloc(struct aead_request *areq, u8 *iv, -- 2.13.3