From patchwork Thu Oct 12 22:45:44 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: 10003059 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 9EF2960325 for ; Thu, 12 Oct 2017 22:47:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9039128E5D for ; Thu, 12 Oct 2017 22:47:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 84FFA28E8B; Thu, 12 Oct 2017 22:47:20 +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 2157128E5D for ; Thu, 12 Oct 2017 22:47:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757291AbdJLWrS (ORCPT ); Thu, 12 Oct 2017 18:47:18 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:37809 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753405AbdJLWrO (ORCPT ); Thu, 12 Oct 2017 18:47:14 -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=1507848435; x=1539384435; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=0hdO5Rh2xSo3AlB33RIykp01qPdvkWBqHjmKn00UvI0=; b=SLddObSYgZJh84OY2tRyPM2IqBuQyf/Yc8sXquEInA8nZMM4QPp8/urM j1ZARvngYOqBZlI0xf6WFknZiEfxpv+IqnlL+e1LZ6yuGywq3w5Bu43P5 aMym6BSJG2S/UbrpN7jX+Aqw1jGXeDj2NqcHXIvKQ6pRVNQyFXANEQGMr nzVL0VGna9DVtfcdTaR8YNv5jICP4Ix9ZZhsU/2wnhQAEjdgbsA4mUpET pY9YYdGLvUm5LVZ30mt1hPQnpUkkC9lQQtK0bKSfyj4+8NE/oBSY5rNKo UFXRW71QokMDRvKzi78V3Flp+oeEMsNTXkLU69ygVU02Tb4Ebx9nuf1FQ w==; X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="58103851" Received: from sjappemgw12.hgst.com (HELO sjappemgw11.hgst.com) ([199.255.44.66]) by ob1.hgst.iphmx.com with ESMTP; 13 Oct 2017 06:47:13 +0800 Received: from thinkpad-bart.sdcorp.global.sandisk.com (HELO thinkpad-bart.int.fusionio.com) ([10.11.172.152]) by sjappemgw11.hgst.com with ESMTP; 12 Oct 2017 15:45:51 -0700 From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, linux-nvme@lists.infradead.org, Bart Van Assche , Ard Biesheuvel , Herbert Xu Subject: [PATCH 2/8] crypto: scompress - use sgl_alloc() and sgl_free() Date: Thu, 12 Oct 2017 15:45:44 -0700 Message-Id: <20171012224550.25440-3-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171012224550.25440-1-bart.vanassche@wdc.com> References: <20171012224550.25440-1-bart.vanassche@wdc.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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 --- crypto/Kconfig | 1 + crypto/scompress.c | 52 +++------------------------------------------------- 2 files changed, 4 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..ea4d5a3e01d1 100644 --- a/crypto/scompress.c +++ b/crypto/scompress.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -140,53 +141,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 +174,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, NULL, GFP_ATOMIC); if (!req->dst) goto out; } @@ -274,7 +228,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;