From patchwork Tue Nov 5 12:37:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 178493 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp698904ilf; Tue, 5 Nov 2019 04:38:26 -0800 (PST) X-Google-Smtp-Source: APXvYqyRPVwMMEPFibiwQ3fXZnWCu+s+d1+jUQm3xbwUtJikrzotr1NFeqKMdbiKZm+qrP1rd54O X-Received: by 2002:a17:906:2a89:: with SMTP id l9mr29285113eje.329.1572957506278; Tue, 05 Nov 2019 04:38:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572957506; cv=none; d=google.com; s=arc-20160816; b=ZpK8sF4v1VS4Clb2wmFLUKQMbT2RT+Y5D1myrUZSaQ20dTzLwwmAD+CmH+M8gDmtAO KTvTtTfbP/iwn/XkiR19J5WehgZGHmsasH4ujSMm02EEBjYsa9aRM2KQpApLTLt9LjZW azApudLZTkOxgdX1TfTB0qmnpaPCcY5AqhTBeiaMzEUpCw0IHk1yFuqVAE519lDp0Y6c LXauvyD0WPyYoawMOwPkNoXiKdfQ7T64Nx88mQ2nb3M39G7ayDSyediZCB3dXnyvgBW+ W5wjQqIocaSIr8/E3JeIgRRiMtjcTe+c3W0q5RlVaoOuiZSrNIGJgDz4lHqhdutsaeJC 7c7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=9fJAHIVAgIN3PPmEYUALLZCyp9Oxs8DgQg19svNGF8c=; b=comkkYo1VzTWK1JLZXPmEOmSiRgKncaKzp5jQ7nEdlit1vH9r7NNhZNfXQqFXlWdwS JXlkQuCNV9FqjNkyjE5PEYZmQzwS51ucc1dQtwVhBy3qLXg7VxtJE72ugD2pPQreYSwa SMBhBlNTljAUlNiuS75xYl5h+oyfVaqkbLxoyhIoZt/3Qvy/QIBbyH5uzYdWA9Ig0xTV F+jDVRn+dZmgVP7+9vOCLFcc+0Kh87f95gNhKCtcSEheldPOQs6+w/dkIRYmoSP7l3ED BdItAUALGvxkCVNeEQQOA4BpB4TgchHMvDUr5Zj5lSE1TcYfuvkVMh2Ef+Ie2qiwo8Xu Xw3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=g87CMXH9; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l3si4323152ejr.86.2019.11.05.04.38.26; Tue, 05 Nov 2019 04:38:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=g87CMXH9; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388772AbfKEMiZ (ORCPT + 3 others); Tue, 5 Nov 2019 07:38:25 -0500 Received: from lelv0142.ext.ti.com ([198.47.23.249]:34590 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388673AbfKEMiZ (ORCPT ); Tue, 5 Nov 2019 07:38:25 -0500 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id xA5CcJEv078729; Tue, 5 Nov 2019 06:38:19 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1572957499; bh=9fJAHIVAgIN3PPmEYUALLZCyp9Oxs8DgQg19svNGF8c=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=g87CMXH98KfwAWINi6aRZrotSBkpUsPkUyBjRvB52obBmubAwDHe47a3rkgWT26Wy bvaTEdVFDNXixWnE3Dj0Qpfvhltn0l8rHQxWBpC8+Hq1ZPFhy+vAwn1zCb4QksL3ID cfcZ73APmynJhqoq70g85/1VYcXSp+mwn+YmvqmI= Received: from DLEE113.ent.ti.com (dlee113.ent.ti.com [157.170.170.24]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id xA5CcJTo023630 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 5 Nov 2019 06:38:19 -0600 Received: from DLEE113.ent.ti.com (157.170.170.24) by DLEE113.ent.ti.com (157.170.170.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 5 Nov 2019 06:38:03 -0600 Received: from fllv0039.itg.ti.com (10.64.41.19) by DLEE113.ent.ti.com (157.170.170.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Tue, 5 Nov 2019 06:38:03 -0600 Received: from sokoban.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id xA5Cc6d3117093; Tue, 5 Nov 2019 06:38:17 -0600 From: Tero Kristo To: , , CC: , Subject: [PATCH 6/6] crypto: omap-crypto: copy the temporary data to output buffer properly Date: Tue, 5 Nov 2019 14:37:59 +0200 Message-ID: <20191105123759.25053-7-t-kristo@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191105123759.25053-1-t-kristo@ti.com> References: <20191105123759.25053-1-t-kristo@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Both source and destination are scatterlists that can contain multiple entries under the omap crypto cleanup handling. Current code only copies data from the first source scatterlist entry to the target scatterlist, potentially omitting any sg entries following the first one. Instead, implement a new routine that walks through both source and target and copies the data over once it goes. Signed-off-by: Tero Kristo --- drivers/crypto/omap-crypto.c | 37 +++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) -- 2.17.1 -- Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki diff --git a/drivers/crypto/omap-crypto.c b/drivers/crypto/omap-crypto.c index 7d592d93bb1c..cc88b7362bc2 100644 --- a/drivers/crypto/omap-crypto.c +++ b/drivers/crypto/omap-crypto.c @@ -154,6 +154,41 @@ int omap_crypto_align_sg(struct scatterlist **sg, int total, int bs, } EXPORT_SYMBOL_GPL(omap_crypto_align_sg); +static void omap_crypto_copy_data(struct scatterlist *src, + struct scatterlist *dst, + int offset, int len) +{ + int amt; + void *srcb, *dstb; + int srco = 0, dsto = offset; + + while (src && dst && len) { + if (srco >= src->length) { + srco -= src->length; + src = sg_next(src); + continue; + } + + if (dsto >= dst->length) { + dsto -= dst->length; + dst = sg_next(dst); + continue; + } + + amt = min(src->length - srco, dst->length - dsto); + amt = min(len, amt); + + srcb = sg_virt(src) + srco; + dstb = sg_virt(dst) + dsto; + + memcpy(dstb, srcb, amt); + + srco += amt; + dsto += amt; + len -= amt; + } +} + void omap_crypto_cleanup(struct scatterlist *sg, struct scatterlist *orig, int offset, int len, u8 flags_shift, unsigned long flags) @@ -171,7 +206,7 @@ void omap_crypto_cleanup(struct scatterlist *sg, struct scatterlist *orig, pages = get_order(len); if (orig && (flags & OMAP_CRYPTO_COPY_MASK)) - scatterwalk_map_and_copy(buf, orig, offset, len, 1); + omap_crypto_copy_data(sg, orig, offset, len); if (flags & OMAP_CRYPTO_DATA_COPIED) free_pages((unsigned long)buf, pages);