aboutsummaryrefslogtreecommitdiff
path: root/lib/scatterlist.c
diff options
context:
space:
mode:
authorMaxim Levitsky <maximlevitsky@gmail.com>2012-09-27 12:45:28 +0200
committerJens Axboe <axboe@kernel.dk>2012-09-27 12:45:28 +0200
commit2e484610296b25f0a04b516bc144a00731d1d845 (patch)
treed45467ec0b7c2446652e685b270427183471a5ad /lib/scatterlist.c
parentc2b1ad800b66f62105a7fd250604d72e07202e66 (diff)
downloadlinux-linaro-stable-2e484610296b25f0a04b516bc144a00731d1d845.tar.gz
scatterlist: add sg_nents
Useful helper to know the number of entries in scatterlist. Signed-off-by: Maxim Levitsky <maximlevitsky@gmail.com> Cc: Alex Dubov <oakad@yahoo.com> Acked-by: Tejun Heo <tj@kernel.org> Cc: Jens Axboe <axboe@kernel.dk> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'lib/scatterlist.c')
-rw-r--r--lib/scatterlist.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/scatterlist.c b/lib/scatterlist.c
index fadae774a20c..1bf60efb5e02 100644
--- a/lib/scatterlist.c
+++ b/lib/scatterlist.c
@@ -39,6 +39,28 @@ struct scatterlist *sg_next(struct scatterlist *sg)
EXPORT_SYMBOL(sg_next);
/**
+ * sg_nents - return total count of entries in scatterlist
+ * @sg: The scatterlist
+ *
+ * Description:
+ * Allows to know how many entries are in sg, taking into acount
+ * chaining as well
+ *
+ **/
+int sg_nents(struct scatterlist *sg)
+{
+ int nents = 0;
+ while (sg) {
+ nents++;
+ sg = sg_next(sg);
+ }
+
+ return nents;
+}
+EXPORT_SYMBOL(sg_nents);
+
+
+/**
* sg_last - return the last scatterlist entry in a list
* @sgl: First entry in the scatterlist
* @nents: Number of entries in the scatterlist