From patchwork Tue Sep 22 16:33:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tadeusz Struk X-Patchwork-Id: 7241041 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 24755BEEC1 for ; Tue, 22 Sep 2015 16:36:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4AE3220668 for ; Tue, 22 Sep 2015 16:36:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5C00120173 for ; Tue, 22 Sep 2015 16:36:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758742AbbIVQfz (ORCPT ); Tue, 22 Sep 2015 12:35:55 -0400 Received: from mga09.intel.com ([134.134.136.24]:30315 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758699AbbIVQfw (ORCPT ); Tue, 22 Sep 2015 12:35:52 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP; 22 Sep 2015 09:35:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,574,1437462000"; d="scan'208";a="566353732" Received: from tstruk-mobl1.jf.intel.com (HELO [127.0.1.1]) ([134.134.171.70]) by FMSMGA003.fm.intel.com with ESMTP; 22 Sep 2015 09:35:52 -0700 Subject: [PATCH v3 1/2] lib/scatterlist: Add sg_len helper From: Tadeusz Struk To: herbert@gondor.apana.org.au Cc: linux-crypto@vger.kernel.org, qat-linux@intel.com, tadeusz.struk@intel.com Date: Tue, 22 Sep 2015 09:33:58 -0700 Message-ID: <20150922163357.18101.68220.stgit@tstruk-mobl1> In-Reply-To: <20150922163352.18101.85685.stgit@tstruk-mobl1> References: <20150922163352.18101.85685.stgit@tstruk-mobl1> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 Add sg_len function which returns the total number of bytes in sg. Signed-off-by: Tadeusz Struk --- include/linux/scatterlist.h | 1 + lib/scatterlist.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h index 556ec1e..dba8f78 100644 --- a/include/linux/scatterlist.h +++ b/include/linux/scatterlist.h @@ -242,6 +242,7 @@ static inline void *sg_virt(struct scatterlist *sg) } int sg_nents(struct scatterlist *sg); +unsigned int sg_len(struct scatterlist *sg); int sg_nents_for_len(struct scatterlist *sg, u64 len); struct scatterlist *sg_next(struct scatterlist *); struct scatterlist *sg_last(struct scatterlist *s, unsigned int); diff --git a/lib/scatterlist.c b/lib/scatterlist.c index bafa993..2ae4c53 100644 --- a/lib/scatterlist.c +++ b/lib/scatterlist.c @@ -57,6 +57,26 @@ int sg_nents(struct scatterlist *sg) EXPORT_SYMBOL(sg_nents); /** + * sg_len - return total size of bytes in the scatterlist + * @sg: The scatterlist + * + * Description: + * Allows to know the total size of bytes in an sg, taking into account + * chaining as well. + * + * Returns: total size of bytes in the scatterlist + **/ +unsigned int sg_len(struct scatterlist *sg) +{ + unsigned int len; + + for (len = 0; sg; sg = sg_next(sg)) + len += sg->length; + return len; +} +EXPORT_SYMBOL(sg_len); + +/** * sg_nents_for_len - return total count of entries in scatterlist * needed to satisfy the supplied length * @sg: The scatterlist