Received: by 10.223.176.5 with SMTP id f5csp1020123wra; Fri, 2 Feb 2018 09:49:41 -0800 (PST) X-Google-Smtp-Source: AH8x227nqiAmOawRoh7iBgikWAv/qXFODCffnlTsd6y7xX6Qoh3EBxQGh/y+5Jkj1naUb1E7kLqR X-Received: by 2002:a17:902:50e:: with SMTP id 14-v6mr35387045plf.360.1517593781208; Fri, 02 Feb 2018 09:49:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517593781; cv=none; d=google.com; s=arc-20160816; b=f7PfNtjaWsRUXL/ohLFrasLX8PYXhsTIQ9isij68mCcZGVPuoSw/jpP7W0JCOs/ENp xO4O6oQxvstherAzY2Dd/OcIyDXIjW80asvehgRRVipfCaqfU7qPvioLZqE+GKipsyK+ GSyn9vvldO6d3SQ4je9Fpc/iHzujIxqKi1HiGiBbvUTPqxtItK4WK8pzqynA9yr7SzJ8 mJDtIGt8se2MGjpp51COLK2QcbB+SBS+TvVyDFbB1s2yAJFUTinS4rTU8oZJRqPcikWB OgyjLt42rDgXYdudozQs4rpRX0zS4GFFyCLxenb47l6d6k6pKHmeP1e8W3u1aimdOOy2 yrbw== 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=EQqOjFUFjHzFWmuM16Vwqze0/PE8plPVJS37RUORFGw=; b=S4peWio3bfHgeK2KHIXJzNdCLBIswGZ0oqrmjG9iZVQzr74QzxSViS3WVkrPdq7nml G44i0ALIIrjirSdejI7GNm/OJe1tV7O6V5AOaDKbac9anKW4t7GcTxV6xN98vYKNh0sz /7/f7pdE31tgTYuUAS2Bn7yw1CfGn93OQvGfem8zHJ6lsMXdsTtJPtIJIIrqBeCIHoG5 ta9phKiCn1K68zfYhVPIbJa5fUR5IhURDaqUX0hP4Mj+Axq1P1BDI4xpYNY/nZuD7dVr UCHXZCh7wrtolRp3NtxgzBkKS6fHsPq97+JHsK6SCCDl6BhRkW9GoQ91DEWDlXorgsow A7GA== 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 66-v6si2212791pla.131.2018.02.02.09.49.26; Fri, 02 Feb 2018 09:49:41 -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 S1753544AbeBBRNy (ORCPT + 99 others); Fri, 2 Feb 2018 12:13:54 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:37050 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752742AbeBBRHd (ORCPT ); Fri, 2 Feb 2018 12:07:33 -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 30EDBEE6; Fri, 2 Feb 2018 17:07:32 +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.14 017/156] crypto: inside-secure - avoid unmapping DMA memory that was not mapped Date: Fri, 2 Feb 2018 17:56:38 +0100 Message-Id: <20180202140841.092331685@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140840.242829545@linuxfoundation.org> References: <20180202140840.242829545@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.14-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 @@ -33,6 +33,8 @@ struct safexcel_ahash_req { bool finish; bool hmac; + int nents; + u8 state_sz; /* expected sate size, only set once */ u32 state[SHA256_DIGEST_SIZE / sizeof(u32)]; @@ -151,8 +153,10 @@ static int safexcel_handle_result(struct result_sz = crypto_ahash_digestsize(ahash); memcpy(sreq->state, areq->result, result_sz); - 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); @@ -177,7 +181,7 @@ static int safexcel_ahash_send(struct cr 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)) @@ -247,15 +251,15 @@ static int safexcel_ahash_send(struct cr } /* 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 */