From patchwork Tue Nov 5 14:01:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 178518 Delivered-To: patch@linaro.org Received: by 2002:ac9:3c86:0:0:0:0:0 with SMTP id w6csp710308ocf; Tue, 5 Nov 2019 06:02:10 -0800 (PST) X-Google-Smtp-Source: APXvYqzDlZmvJqqPHoL02NsU3S9Sx8IgUlmOxwbSANsQm7dvjiSI5e2Rc2Nb9Qa+oJRc5mC82T8f X-Received: by 2002:a05:6402:158d:: with SMTP id c13mr19690115edv.62.1572962530316; Tue, 05 Nov 2019 06:02:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572962530; cv=none; d=google.com; s=arc-20160816; b=k9qL77VJA7vkhy0ZBbDn1E4/Xz+wIrF6nzFzQV/76uNXg+QX1db7U+XJVCLaPft8bd IkK6w3FUEI2gZsJ+pCck0Ko6HmIGnxs9NXvhEk7eFKXthQl5pWDon++9M6ZtKDbh/snZ 3OBOITJKzGzznOC1JGl2/J23x9LgTAfSIFA2jk2Z22icGEvN7AYo8Owz1SmEVUKR2XKb JbQAo6w1eq9+DRnScumaGOG97WTHHLnf29MSA2r89Phi43vFjKXDtvAFRpYPbrTMg7Lf 4yFWvmo1CqF4qrfjDIl8da+3fo9byXWf7Tj3myaQjrqGRLIfxoF05yXHUiwaHfwEms5Z lrOg== 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=js6ZZjmY9uSLytMfQgRanKpF4C83gpp4ICwyaDMCt637NcWboidb8+5HF4fs8WSgAI LhQrzouJME2mTgj23dPcOtnzkaDtpxObnfmXDokYNreJAGrddbjPv3UcRQi7y3bWhv4V iFY3fGm4sZ1omeRhFyC0Szl0ndR3D9ECFpzyQWwQEJdjAAoNEz1Ra7pShbGrClm6LuYi Xyx7SrIMNBfaZLdiI9qqTf+rFfHSDNqLTlLm9yuOSZadb6KSbF4pBpJ0kbgZm8JTIbQI At+W2ZasxpCmLvU/BMmUIHAXABOWtkdWLe33KK+awNZLxS2ekKtK7PLRKIQg71a5k3n9 pjrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=HbLRw8kg; spf=pass (google.com: best guess record for domain of linux-omap-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-omap-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 dk11si13340421ejb.97.2019.11.05.06.02.10; Tue, 05 Nov 2019 06:02:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-omap-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=HbLRw8kg; spf=pass (google.com: best guess record for domain of linux-omap-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-omap-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 S2389449AbfKEOCJ (ORCPT + 5 others); Tue, 5 Nov 2019 09:02:09 -0500 Received: from lelv0143.ext.ti.com ([198.47.23.248]:35274 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389342AbfKEOCJ (ORCPT ); Tue, 5 Nov 2019 09:02:09 -0500 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id xA5E24h4038298; Tue, 5 Nov 2019 08:02:04 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1572962524; bh=9fJAHIVAgIN3PPmEYUALLZCyp9Oxs8DgQg19svNGF8c=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=HbLRw8kgswNEXHxEe2P87lvRkRS3yxuXfOAO8ILecB6xsNbpf7qQuIcWRaguB4xwo HgqnEMOTJgCoTdbDwzDzLFg+NzS33ufa4GqNpT5KNslDGkIt0bOw1HOqAn5u88cv2d cQNxQNj/pPlJqbn7i+wnjn0SfiOXzxnF1JAfH2sk= Received: from DLEE107.ent.ti.com (dlee107.ent.ti.com [157.170.170.37]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTP id xA5E23Rm085039; Tue, 5 Nov 2019 08:02:03 -0600 Received: from DLEE112.ent.ti.com (157.170.170.23) by DLEE107.ent.ti.com (157.170.170.37) 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 08:02:03 -0600 Received: from fllv0040.itg.ti.com (10.64.41.20) by DLEE112.ent.ti.com (157.170.170.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3 via Frontend Transport; Tue, 5 Nov 2019 08:02:03 -0600 Received: from sokoban.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id xA5E1FG1068289; Tue, 5 Nov 2019 08:02:01 -0600 From: Tero Kristo To: , , CC: , Subject: [PATCHv2 22/22] crypto: omap-crypto: copy the temporary data to output buffer properly Date: Tue, 5 Nov 2019 16:01:11 +0200 Message-ID: <20191105140111.20285-23-t-kristo@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191105140111.20285-1-t-kristo@ti.com> References: <20191105140111.20285-1-t-kristo@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@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);