Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2318979pxb; Mon, 20 Sep 2021 18:41:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzupUxR6EDWShEd4v4Em0FBuekx/G6qlkPugK93A/gOdJWFyZfnwDLRr42SzuvKYWRcXUIu X-Received: by 2002:a92:c041:: with SMTP id o1mr19958107ilf.193.1632188498691; Mon, 20 Sep 2021 18:41:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632188498; cv=none; d=google.com; s=arc-20160816; b=UjAzolvDDTALNebsOOrdQJzte0/GNcvNkqou0nFXiRQwbZNQ8/fKqhTjwlAciP0dNq V74kEBe2Xs1Uy3OOZ71ypxuqdedl+/snaGyk6oz7KMjVDW4NO9IiUb30+SWChiSiKKJI X2/juJXExuScu0iD0NduWuyE7aYKwpaw9LWhcCk9x1Lpv1279Aye8UDgRBnPmH1gbqg6 LuhF63t4O8bNtRH0dyXGvfPd4BtpanAGZc2JNZ8u4++QtTT8Bukv7RSEEaEbuRCuazsD OgCylYm8fGSntH0VNi4UwN3V9iEorzJJXZXghs/4x8nGP3epbREMFhSMD76ytteblYZg H+2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=h19SzMxB6aENxmElhV01DuTTxU2G/lh0Ock6mR+dlyU=; b=N4Zppw+Mzc2dfYR3GiEuxHLVA5kpt0eeX46zjinfyow4ux9/gU1NjqhQ/BqQc4xjBs j0nyFVyIa7xzC2w62Oq12vo9HokrUCo7fn7i26KrcEZWCO8c7xSCaeSaelbuDMmIFLMi mvRyvMqZXPhwtqrl3q5X3WP770VlEUHOOXVGk6VTtpN3J4SLMHwW4ZDFIXJXNHkZgboj /sFDu2JjmJ06Iv3qmI5Qh1yTueiOMKx2HowoOPX0nYD2Q1053DI8AljbjqAYp5k5GOWX uMk78QRTKHmIueLeBEocyRmtELPb4f4rWbcUCFnF9kyClPLtm/VWFyqUcDEjH9IZB2wi Clyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EBYK7uAZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l20si579149jad.72.2021.09.20.18.41.27; Mon, 20 Sep 2021 18:41:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EBYK7uAZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240505AbhITQtw (ORCPT + 99 others); Mon, 20 Sep 2021 12:49:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:36634 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243993AbhITQs5 (ORCPT ); Mon, 20 Sep 2021 12:48:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1E20761352; Mon, 20 Sep 2021 16:47:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632156443; bh=wPiuuRs1GwINMb4+sI5mglAP/2anBVTtPw4O64CAFsc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EBYK7uAZEqeJgZFppkLhVdgfYTEwx23dvC2OZGf86dD9TmGWlUDMx50rJ+ujxqRA6 KbjIW98p/JptO7Ty7pseslT6zj5NC4icQ/wCcjyoq5KrZY21yvlmN703YrTDfpROlD v6+rzQAGceuHsZOLxaprdOI9Pb67E4VtH0WHMRG0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Anderson , Richard Weinberger , Herbert Xu , Sasha Levin Subject: [PATCH 4.4 029/133] crypto: mxs-dcp - Check for DMA mapping errors Date: Mon, 20 Sep 2021 18:41:47 +0200 Message-Id: <20210920163913.571898573@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163912.603434365@linuxfoundation.org> References: <20210920163912.603434365@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Anderson [ Upstream commit df6313d707e575a679ada3313358289af24454c0 ] After calling dma_map_single(), we must also call dma_mapping_error(). This fixes the following warning when compiling with CONFIG_DMA_API_DEBUG: [ 311.241478] WARNING: CPU: 0 PID: 428 at kernel/dma/debug.c:1027 check_unmap+0x79c/0x96c [ 311.249547] DMA-API: mxs-dcp 2280000.crypto: device driver failed to check map error[device address=0x00000000860cb080] [size=32 bytes] [mapped as single] Signed-off-by: Sean Anderson Reviewed-by: Richard Weinberger Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- drivers/crypto/mxs-dcp.c | 45 +++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/drivers/crypto/mxs-dcp.c b/drivers/crypto/mxs-dcp.c index 1a8dc76e117e..c94db361138d 100644 --- a/drivers/crypto/mxs-dcp.c +++ b/drivers/crypto/mxs-dcp.c @@ -167,15 +167,19 @@ static struct dcp *global_sdcp; static int mxs_dcp_start_dma(struct dcp_async_ctx *actx) { + int dma_err; struct dcp *sdcp = global_sdcp; const int chan = actx->chan; uint32_t stat; unsigned long ret; struct dcp_dma_desc *desc = &sdcp->coh->desc[actx->chan]; - dma_addr_t desc_phys = dma_map_single(sdcp->dev, desc, sizeof(*desc), DMA_TO_DEVICE); + dma_err = dma_mapping_error(sdcp->dev, desc_phys); + if (dma_err) + return dma_err; + reinit_completion(&sdcp->completion[chan]); /* Clear status register. */ @@ -213,18 +217,29 @@ static int mxs_dcp_start_dma(struct dcp_async_ctx *actx) static int mxs_dcp_run_aes(struct dcp_async_ctx *actx, struct ablkcipher_request *req, int init) { + dma_addr_t key_phys, src_phys, dst_phys; struct dcp *sdcp = global_sdcp; struct dcp_dma_desc *desc = &sdcp->coh->desc[actx->chan]; struct dcp_aes_req_ctx *rctx = ablkcipher_request_ctx(req); int ret; - dma_addr_t key_phys = dma_map_single(sdcp->dev, sdcp->coh->aes_key, - 2 * AES_KEYSIZE_128, - DMA_TO_DEVICE); - dma_addr_t src_phys = dma_map_single(sdcp->dev, sdcp->coh->aes_in_buf, - DCP_BUF_SZ, DMA_TO_DEVICE); - dma_addr_t dst_phys = dma_map_single(sdcp->dev, sdcp->coh->aes_out_buf, - DCP_BUF_SZ, DMA_FROM_DEVICE); + key_phys = dma_map_single(sdcp->dev, sdcp->coh->aes_key, + 2 * AES_KEYSIZE_128, DMA_TO_DEVICE); + ret = dma_mapping_error(sdcp->dev, key_phys); + if (ret) + return ret; + + src_phys = dma_map_single(sdcp->dev, sdcp->coh->aes_in_buf, + DCP_BUF_SZ, DMA_TO_DEVICE); + ret = dma_mapping_error(sdcp->dev, src_phys); + if (ret) + goto err_src; + + dst_phys = dma_map_single(sdcp->dev, sdcp->coh->aes_out_buf, + DCP_BUF_SZ, DMA_FROM_DEVICE); + ret = dma_mapping_error(sdcp->dev, dst_phys); + if (ret) + goto err_dst; if (actx->fill % AES_BLOCK_SIZE) { dev_err(sdcp->dev, "Invalid block size!\n"); @@ -262,10 +277,12 @@ static int mxs_dcp_run_aes(struct dcp_async_ctx *actx, ret = mxs_dcp_start_dma(actx); aes_done_run: + dma_unmap_single(sdcp->dev, dst_phys, DCP_BUF_SZ, DMA_FROM_DEVICE); +err_dst: + dma_unmap_single(sdcp->dev, src_phys, DCP_BUF_SZ, DMA_TO_DEVICE); +err_src: dma_unmap_single(sdcp->dev, key_phys, 2 * AES_KEYSIZE_128, DMA_TO_DEVICE); - dma_unmap_single(sdcp->dev, src_phys, DCP_BUF_SZ, DMA_TO_DEVICE); - dma_unmap_single(sdcp->dev, dst_phys, DCP_BUF_SZ, DMA_FROM_DEVICE); return ret; } @@ -570,6 +587,10 @@ static int mxs_dcp_run_sha(struct ahash_request *req) dma_addr_t buf_phys = dma_map_single(sdcp->dev, sdcp->coh->sha_in_buf, DCP_BUF_SZ, DMA_TO_DEVICE); + ret = dma_mapping_error(sdcp->dev, buf_phys); + if (ret) + return ret; + /* Fill in the DMA descriptor. */ desc->control0 = MXS_DCP_CONTROL0_DECR_SEMAPHORE | MXS_DCP_CONTROL0_INTERRUPT | @@ -602,6 +623,10 @@ static int mxs_dcp_run_sha(struct ahash_request *req) if (rctx->fini) { digest_phys = dma_map_single(sdcp->dev, sdcp->coh->sha_out_buf, DCP_SHA_PAY_SZ, DMA_FROM_DEVICE); + ret = dma_mapping_error(sdcp->dev, digest_phys); + if (ret) + goto done_run; + desc->control0 |= MXS_DCP_CONTROL0_HASH_TERM; desc->payload = digest_phys; } -- 2.30.2