From patchwork Thu Sep 10 13:21:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 7154141 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 189BC9F326 for ; Thu, 10 Sep 2015 13:22:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3870A20882 for ; Thu, 10 Sep 2015 13:22:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A09B320881 for ; Thu, 10 Sep 2015 13:22:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753818AbbIJNV5 (ORCPT ); Thu, 10 Sep 2015 09:21:57 -0400 Received: from mail-wi0-f173.google.com ([209.85.212.173]:33685 "EHLO mail-wi0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751263AbbIJNVv (ORCPT ); Thu, 10 Sep 2015 09:21:51 -0400 Received: by wiclk2 with SMTP id lk2so28111806wic.0; Thu, 10 Sep 2015 06:21:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FvkpS5pdzBnvhGA+3o9OMoN3/3qNiMZK5pfu/WPukCI=; b=LDBl1csQMxtOdE1dRa4mo5OM1IMh70zsMivAqbX3YmBSGUZSnROXG88sioDeer5KTj 0Tzrg5JwXqOZQXDMOfrq4qu5WWobfaZhxh57s/yhFPF2KFryXk0M36FrdAyD5CFZ2mps jEWq4eVZqbcaNa55wjw6sPM69Q8vko6Z3PJqf/rnO4aorgfN5RxdpvI/gpEPQkTb6SNu C3CA0utWe0LJ4DxFpqJ1rTOkdTVtnbRZxnrp2qMs1sCFh63IYuwO07YFdKboiYXLQk67 bhf5zl4UpWAyowfldx6QwKKJJUeSpGC7XVNpgU5g6z/qCgTpSJ9pBbS5Y8fagd1Qsk7e tqIA== X-Received: by 10.181.12.20 with SMTP id em20mr6596606wid.28.1441891310396; Thu, 10 Sep 2015 06:21:50 -0700 (PDT) Received: from Red.local (ANice-651-1-384-228.w86-205.abo.wanadoo.fr. [86.205.16.228]) by smtp.googlemail.com with ESMTPSA id h6sm9354122wiy.3.2015.09.10.06.21.49 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 10 Sep 2015 06:21:50 -0700 (PDT) From: LABBE Corentin To: herbert@gondor.apana.org.au, davem@davemloft.net Cc: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, LABBE Corentin Subject: [PATCH 5/7] crypto: talitos replace sg_count with sg_nents_for_len2 Date: Thu, 10 Sep 2015 15:21:40 +0200 Message-Id: <1441891302-12014-6-git-send-email-clabbe.montjoie@gmail.com> X-Mailer: git-send-email 2.4.6 In-Reply-To: <1441891302-12014-1-git-send-email-clabbe.montjoie@gmail.com> References: <1441891302-12014-1-git-send-email-clabbe.montjoie@gmail.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: LABBE Corentin --- drivers/crypto/talitos.c | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index 3b20a1b..aca6a6a 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c @@ -1234,26 +1234,6 @@ static int ipsec_esp(struct talitos_edesc *edesc, struct aead_request *areq, } /* - * derive number of elements in scatterlist - */ -static int sg_count(struct scatterlist *sg_list, int nbytes, bool *chained) -{ - struct scatterlist *sg = sg_list; - int sg_nents = 0; - - *chained = false; - while (nbytes > 0 && sg) { - sg_nents++; - nbytes -= sg->length; - if (!sg_is_last(sg) && (sg + 1)->length == 0) - *chained = true; - sg = sg_next(sg); - } - - return sg_nents; -} - -/* * allocate and map the extended descriptor */ static struct talitos_edesc *talitos_edesc_alloc(struct device *dev, @@ -1287,16 +1267,17 @@ static struct talitos_edesc *talitos_edesc_alloc(struct device *dev, iv_dma = dma_map_single(dev, iv, ivsize, DMA_TO_DEVICE); if (!dst || dst == src) { - src_nents = sg_count(src, assoclen + cryptlen + authsize, - &src_chained); + src_nents = sg_nents_for_len2(src, + assoclen + cryptlen + authsize, + &src_chained); src_nents = (src_nents == 1) ? 0 : src_nents; dst_nents = dst ? src_nents : 0; } else { /* dst && dst != src*/ - src_nents = sg_count(src, assoclen + cryptlen + + src_nents = sg_nents_for_len2(src, assoclen + cryptlen + (encrypt ? 0 : authsize), &src_chained); src_nents = (src_nents == 1) ? 0 : src_nents; - dst_nents = sg_count(dst, assoclen + cryptlen + + dst_nents = sg_nents_for_len2(dst, assoclen + cryptlen + (encrypt ? authsize : 0), &dst_chained); dst_nents = (dst_nents == 1) ? 0 : dst_nents; @@ -1902,7 +1883,8 @@ static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes) if (!req_ctx->last && (nbytes + req_ctx->nbuf <= blocksize)) { /* Buffer up to one whole block */ sg_copy_to_buffer(areq->src, - sg_count(areq->src, nbytes, &chained), + sg_nents_for_len2(areq->src, nbytes, + &chained), req_ctx->buf + req_ctx->nbuf, nbytes); req_ctx->nbuf += nbytes; return 0; @@ -1935,7 +1917,7 @@ static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes) req_ctx->psrc = areq->src; if (to_hash_later) { - int nents = sg_count(areq->src, nbytes, &chained); + int nents = sg_nents_for_len2(areq->src, nbytes, &chained); sg_pcopy_to_buffer(areq->src, nents, req_ctx->bufnext, to_hash_later,