From patchwork Fri Nov 3 22:23:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10041251 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5C08F603D7 for ; Fri, 3 Nov 2017 22:23:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E874299C4 for ; Fri, 3 Nov 2017 22:23:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 43424299C2; Fri, 3 Nov 2017 22:23:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B82DC299C3 for ; Fri, 3 Nov 2017 22:23:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752454AbdKCWXn (ORCPT ); Fri, 3 Nov 2017 18:23:43 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:46889 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751536AbdKCWXm (ORCPT ); Fri, 3 Nov 2017 18:23:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1509747822; x=1541283822; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=nn24vv5kcgzXlfB+xmt4djcm9aJzwx9NhUDsMNRQRzk=; b=MrMP9ZhB/5PDCBYJxi3wL0CNvUwq+eNslHrRxOZPVudpo4ZWYYQa+yt7 vyYFxVv/vbIOE6uyEVfQ9Ys7ufmTUMk+8e1lcPQ4rTtj7TKRF7yYqgHm2 RF8WWOZG7fLKdB7+ffo85GrEb7kmwILV8s0eVAMcu0Thk/MnHcZa/Sbi8 AwTAsz+kCSVNltAUkaEZ0pJd2WBu8oZGUmjmquGZd1QRbcUlB5AALqVji 6i4WYQFBOdEPOjLsYWXHNQm7wXh1Oc6U8zcDL7q+/2imKvZ2i+Bw3Gv5Q mefCN119wtJAq+VvVDxmnYp1Nkx9qe/B1DH/ITYbq30u/qja9dIxtljS4 g==; X-IronPort-AV: E=Sophos;i="5.44,339,1505750400"; d="scan'208";a="163704782" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 04 Nov 2017 06:23:41 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 03 Nov 2017 15:21:43 -0700 Received: from unknown (HELO MILHUBIP03.sdcorp.global.sandisk.com) ([10.177.9.96]) by uls-op-cesaip02.wdc.com with ESMTP; 03 Nov 2017 15:23:42 -0700 Received: from milsmgip12.sandisk.com (10.177.9.6) by MILHUBIP03.sdcorp.global.sandisk.com (10.177.9.96) with Microsoft SMTP Server id 14.3.319.2; Fri, 3 Nov 2017 15:23:40 -0700 X-AuditID: 0ab1095a-d99e3980000146e4-79-59fcec6cf266 Received: from thinkpad-bart.int.fusionio.com ( [10.177.8.100]) by (Symantec Messaging Gateway) with SMTP id A6.92.18148.C6CECF95; Fri, 3 Nov 2017 15:23:40 -0700 (PDT) From: Bart Van Assche To: Jens Axboe CC: , Christoph Hellwig , "Ard Biesheuvel" , Herbert Xu , Bart Van Assche Subject: [PATCH v3 2/8] crypto: scompress - use sgl_alloc() and sgl_free() Date: Fri, 3 Nov 2017 15:23:33 -0700 Message-ID: <20171103222339.26540-3-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171103222339.26540-1-bart.vanassche@wdc.com> References: <20171103222339.26540-1-bart.vanassche@wdc.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrLJMWRmVeSWpSXmKPExsXCtZEjRTfnzZ9Ig7aVGhb/P+xmtFh9t5/N 4tKfL4wWK1cfZbLofiVjsfeWtgObx7YDqh6Xz5Z63Lm2h81j980GNo/Pm+Q82g90MwWwRXHZ pKTmZJalFunbJXBl7F9/krngkXDFygu3WBsYX/N3MXJySAiYSGyY1cXcxcjFISSwmlFi18Hz 7CAJNgE9iVPz9jGB2CICChI9v1eygRQxCxxnlNh7/i8LSEJYwEti2qKfbCA2i4CqROPOLWAN vALWEnNv/mWF2CAvsfbtPUYQm1PARuLKgiawGiGgmt7OFewTGLkXMDKsYhTLzcwpzk3PLDA0 0itOzEvJLM7WS87P3cQIDhDOqB2M1yeaH2Jk4uCUamB0YhMrtKl4ab3YSdOr701uR8OBsvXS Om+OWbay7TlaLl93vr1cZPlVnugcJauKPzGGf8oLJEPsFtzYsebUvvLojBnCj7KX7o+KT87O /r99iUe6UeqTNxteFDk83uiottB+RQDz5zkVfaJWN6fob+NmEHWeL8Dll+e59/KTZ05prJFB LxiiVyqxFGckGmoxFxUnAgC5XlDJwAEAAA== MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use the sgl_alloc() and sgl_free() functions instead of open coding these functions. Signed-off-by: Bart Van Assche Cc: Ard Biesheuvel Cc: Herbert Xu Acked-by: Ard Biesheuvel --- crypto/Kconfig | 1 + crypto/scompress.c | 51 ++------------------------------------------------- 2 files changed, 3 insertions(+), 49 deletions(-) diff --git a/crypto/Kconfig b/crypto/Kconfig index 0a121f9ddf8e..a0667dd284ff 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig @@ -105,6 +105,7 @@ config CRYPTO_KPP config CRYPTO_ACOMP2 tristate select CRYPTO_ALGAPI2 + select SGL_ALLOC config CRYPTO_ACOMP tristate diff --git a/crypto/scompress.c b/crypto/scompress.c index 2075e2c4e7df..968bbcf65c94 100644 --- a/crypto/scompress.c +++ b/crypto/scompress.c @@ -140,53 +140,6 @@ static int crypto_scomp_init_tfm(struct crypto_tfm *tfm) return ret; } -static void crypto_scomp_sg_free(struct scatterlist *sgl) -{ - int i, n; - struct page *page; - - if (!sgl) - return; - - n = sg_nents(sgl); - for_each_sg(sgl, sgl, n, i) { - page = sg_page(sgl); - if (page) - __free_page(page); - } - - kfree(sgl); -} - -static struct scatterlist *crypto_scomp_sg_alloc(size_t size, gfp_t gfp) -{ - struct scatterlist *sgl; - struct page *page; - int i, n; - - n = ((size - 1) >> PAGE_SHIFT) + 1; - - sgl = kmalloc_array(n, sizeof(struct scatterlist), gfp); - if (!sgl) - return NULL; - - sg_init_table(sgl, n); - - for (i = 0; i < n; i++) { - page = alloc_page(gfp); - if (!page) - goto err; - sg_set_page(sgl + i, page, PAGE_SIZE, 0); - } - - return sgl; - -err: - sg_mark_end(sgl + i); - crypto_scomp_sg_free(sgl); - return NULL; -} - static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir) { struct crypto_acomp *tfm = crypto_acomp_reqtfm(req); @@ -220,7 +173,7 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir) scratch_dst, &req->dlen, *ctx); if (!ret) { if (!req->dst) { - req->dst = crypto_scomp_sg_alloc(req->dlen, GFP_ATOMIC); + req->dst = sgl_alloc(req->dlen, GFP_ATOMIC, NULL); if (!req->dst) goto out; } @@ -274,7 +227,7 @@ int crypto_init_scomp_ops_async(struct crypto_tfm *tfm) crt->compress = scomp_acomp_compress; crt->decompress = scomp_acomp_decompress; - crt->dst_free = crypto_scomp_sg_free; + crt->dst_free = sgl_free; crt->reqsize = sizeof(void *); return 0;