Received: by 10.223.176.5 with SMTP id f5csp1016329wra; Fri, 2 Feb 2018 09:45:42 -0800 (PST) X-Google-Smtp-Source: AH8x227Fw0v6clYZuo3qd0+zisZ2qTaP8nU/6wZW1MsPWtMMJkj7/y7M3xqGw+uh7RDae1iKAc15 X-Received: by 10.101.76.130 with SMTP id m2mr32248334pgt.187.1517593542117; Fri, 02 Feb 2018 09:45:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517593542; cv=none; d=google.com; s=arc-20160816; b=D1ChceVgGBgcKchyDywSTWTsPJgdEV75i8lxYLPTGNaPY7hXReTmhiotjJDle6HSUA gDbIwdYd5h0xt2Wccj168+/QDgHeGlrMypBOWQpA0mTMTvw19a5wB+WUT871x5IA0DFe KpKZpMTyOfCOgI1NQS9cdW3N+hDniL7YqJ1QnQs2FoCFV78aH3VLzRVb4NvK1uotdSgp Y/hTqDFxH3lz597GnbtiURY7OGVBmXGnlGcytSzot/aZnm4N5hctEnMAm6Vole0HQ92j gh/dw12edC4bVhHjP6OUWkwrkTQmlEC6iTSKlYkoY4QHlmhH2bz3t1Jek95Z4o8hiB88 ZE7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=rhSd/rRTkbT8hqKhh5VrFKrCT9Ph3nYQbXKL9V2xyyQ=; b=mVJgvm4G0+BBQXBf6b6Oy9c7uxEQTlfuiCL0ecmG48ya/QwIvNh7cea8EOUspvuTQq +m7ypkpNT1HIRocIhNCS57wScNMJDTiLlfSBQJ4G7Q8kzwV8hudgJEMAnarE1uiPwWhk HF0ZMCfDPifunruzb0PueHMupc2cuBA5U9aGNcGymDA/4qab4e1j4kD9GTH88DubZOTn lwhT9i6FHiGfr9e3Opp5fkxLkIKb1wnZe9VCoMZheh6JofckwotMQjd2IbpiXmGf1Fxv 6N6JgZkzPtGth0sT0jSpjCdpCpdn+b/ZAwCzbZheT+7puAb+82fDtcDxyuH0Bn83ZRe7 5jmA== 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 z3-v6si9276pln.395.2018.02.02.09.45.27; Fri, 02 Feb 2018 09:45:42 -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 S1753163AbeBBRom (ORCPT + 99 others); Fri, 2 Feb 2018 12:44:42 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:40618 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753686AbeBBROz (ORCPT ); Fri, 2 Feb 2018 12:14:55 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id BFC30AD8; Fri, 2 Feb 2018 17:14:54 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Antoine Tenart , Herbert Xu Subject: [PATCH 4.15 13/55] crypto: inside-secure - avoid unmapping DMA memory that was not mapped Date: Fri, 2 Feb 2018 17:58:31 +0100 Message-Id: <20180202140827.337756380@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140826.117602411@linuxfoundation.org> References: <20180202140826.117602411@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Antoine Tenart commit c957f8b3e2e54b29f53ef69decc87bbc858c9b58 upstream. This patch adds a parameter in the SafeXcel ahash request structure to keep track of the number of SG entries mapped. This allows not to call dma_unmap_sg() when dma_map_sg() wasn't called in the first place. This also removes a warning when the debugging of the DMA-API is enabled in the kernel configuration: "DMA-API: device driver tries to free DMA memory it has not allocated". Fixes: 1b44c5a60c13 ("crypto: inside-secure - add SafeXcel EIP197 crypto engine driver") Signed-off-by: Antoine Tenart Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/inside-secure/safexcel_hash.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) --- a/drivers/crypto/inside-secure/safexcel_hash.c +++ b/drivers/crypto/inside-secure/safexcel_hash.c @@ -34,6 +34,8 @@ struct safexcel_ahash_req { bool hmac; bool needs_inv; + int nents; + u8 state_sz; /* expected sate size, only set once */ u32 state[SHA256_DIGEST_SIZE / sizeof(u32)] __aligned(sizeof(u32)); @@ -152,8 +154,10 @@ static int safexcel_handle_req_result(st memcpy(areq->result, sreq->state, crypto_ahash_digestsize(ahash)); - dma_unmap_sg(priv->dev, areq->src, - sg_nents_for_len(areq->src, areq->nbytes), DMA_TO_DEVICE); + if (sreq->nents) { + dma_unmap_sg(priv->dev, areq->src, sreq->nents, DMA_TO_DEVICE); + sreq->nents = 0; + } safexcel_free_context(priv, async, sreq->state_sz); @@ -178,7 +182,7 @@ static int safexcel_ahash_send_req(struc struct safexcel_command_desc *cdesc, *first_cdesc = NULL; struct safexcel_result_desc *rdesc; struct scatterlist *sg; - int i, nents, queued, len, cache_len, extra, n_cdesc = 0, ret = 0; + int i, queued, len, cache_len, extra, n_cdesc = 0, ret = 0; queued = len = req->len - req->processed; if (queued < crypto_ahash_blocksize(ahash)) @@ -248,15 +252,15 @@ static int safexcel_ahash_send_req(struc } /* Now handle the current ahash request buffer(s) */ - nents = dma_map_sg(priv->dev, areq->src, - sg_nents_for_len(areq->src, areq->nbytes), - DMA_TO_DEVICE); - if (!nents) { + req->nents = dma_map_sg(priv->dev, areq->src, + sg_nents_for_len(areq->src, areq->nbytes), + DMA_TO_DEVICE); + if (!req->nents) { ret = -ENOMEM; goto cdesc_rollback; } - for_each_sg(areq->src, sg, nents, i) { + for_each_sg(areq->src, sg, req->nents, i) { int sglen = sg_dma_len(sg); /* Do not overflow the request */