Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Tadeusz Struk <tadeusz.struk@intel.com>
To: herbert@gondor.apana.org.au
Cc: linux-crypto@vger.kernel.org, qat-linux@intel.com,
	tadeusz.struk@intel.com
Subject: [PATCH  v4 1/3] lib/scatterlist: Add sg_len helper
Date: Thu, 01 Oct 2015 13:28:51 -0700	[thread overview]
Message-ID: <20151001202850.7193.77248.stgit@tstruk-mobl1> (raw)
In-Reply-To: <20151001202845.7193.51602.stgit@tstruk-mobl1>

Add sg_len function which returns the total number of bytes in sg.

Signed-off-by: Tadeusz Struk <tadeusz.struk@intel.com>
---
 include/linux/scatterlist.h |    1 +
 lib/scatterlist.c           |   20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)

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

  reply	other threads:[~2015-10-01 20:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-01 20:28 [PATCH v4 0/3] crypto: akcipher - Changes to asymmetric key API Tadeusz Struk
2015-10-01 20:28 ` Tadeusz Struk [this message]
2015-10-01 20:28 ` [PATCH v4 2/3] lib/mpi: Add mpi sgl helpers Tadeusz Struk
2015-10-01 20:29 ` [PATCH v4 3/3] crypto: akcipher - Changes to asymmetric key API Tadeusz Struk
2015-10-02  3:20 ` [PATCH v4 0/3] " Herbert Xu
2015-10-02  3:40   ` Tadeusz Struk
2015-10-02  4:04     ` Herbert Xu
2015-10-02  4:09       ` Tadeusz Struk
2015-10-02  4:14         ` Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151001202850.7193.77248.stgit@tstruk-mobl1 \
    --to=tadeusz.struk@intel.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=qat-linux@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox