diff options
author | Maxim Levitsky <maximlevitsky@gmail.com> | 2012-09-27 12:45:28 +0200 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2012-09-27 12:45:28 +0200 |
commit | 2e484610296b25f0a04b516bc144a00731d1d845 (patch) | |
tree | d45467ec0b7c2446652e685b270427183471a5ad | |
parent | c2b1ad800b66f62105a7fd250604d72e07202e66 (diff) | |
download | op-kernel-dev-2e484610296b25f0a04b516bc144a00731d1d845.zip op-kernel-dev-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>
-rw-r--r-- | include/linux/scatterlist.h | 1 | ||||
-rw-r--r-- | lib/scatterlist.c | 22 |
2 files changed, 23 insertions, 0 deletions
diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h index 7b600da..4bd6c06 100644 --- a/include/linux/scatterlist.h +++ b/include/linux/scatterlist.h @@ -201,6 +201,7 @@ static inline void *sg_virt(struct scatterlist *sg) return page_address(sg_page(sg)) + sg->offset; } +int sg_nents(struct scatterlist *sg); struct scatterlist *sg_next(struct scatterlist *); struct scatterlist *sg_last(struct scatterlist *s, unsigned int); void sg_init_table(struct scatterlist *, unsigned int); diff --git a/lib/scatterlist.c b/lib/scatterlist.c index fadae77..1bf60ef 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 |