From: Tejun Heo <tj@kernel.org>
To: Maxim Levitsky <maximlevitsky@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Alex Dubov <oakad@yahoo.com>,
linux-kernel@vger.kernel.org, Jens Axboe <axboe@kernel.dk>
Subject: Re: [PATCH 1/2] scatterlist: add sg_nents
Date: Wed, 26 Sep 2012 09:38:51 -0700 [thread overview]
Message-ID: <20120926163851.GP16296@google.com> (raw)
In-Reply-To: <1348652941-31899-2-git-send-email-maximlevitsky@gmail.com>
(cc'ing Jens)
On Wed, Sep 26, 2012 at 11:49:00AM +0200, Maxim Levitsky wrote:
> Useful helper to know the number of entries in scatterlist.
>
> Signed-off-by: Maxim Levitsky <maximlevitsky@gmail.com>
> ---
> include/linux/scatterlist.h | 1 +
> lib/scatterlist.c | 22 ++++++++++++++++++++++
> 2 files changed, 23 insertions(+)
>
> 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 e76d85c..5cd9cdc 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);
How about the following instead?
for (nents = 0; sg; sg = sg_next(sg))
nents++;
return nents;
Other than that,
Acked-by: Tejun Heo <tj@kernel.org>
Thanks.
--
tejun
next prev parent reply other threads:[~2012-09-26 16:38 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-26 9:48 [PATCH v3 memstick: support for legacy sony memsticks Maxim Levitsky
2012-09-26 9:49 ` [PATCH 1/2] scatterlist: add sg_nents Maxim Levitsky
2012-09-26 16:38 ` Tejun Heo [this message]
2012-09-27 10:47 ` Jens Axboe
2012-09-27 14:28 ` [PATCH] scatterlist: refactor the sg_nents Maxim Levitsky
2012-09-28 8:37 ` Jens Axboe
2012-10-11 10:27 ` [PATCH 1/2] scatterlist: add sg_nents Geert Uytterhoeven
2012-10-11 10:28 ` Geert Uytterhoeven
2012-09-26 9:49 ` [PATCH 2/2] memstick: add support for legacy memorysticks Maxim Levitsky
2012-09-26 16:41 ` Tejun Heo
2012-09-29 17:20 ` Geert Uytterhoeven
2012-10-01 20:24 ` Maxim Levitsky
2012-10-08 15:36 ` Fixes for ms_block Maxim Levitsky
2012-10-08 15:36 ` [PATCH 1/2] memstick: remove unused field from state struct Maxim Levitsky
2012-10-08 15:36 ` [PATCH 2/2] memstick: ms_block: fix complile issue Maxim Levitsky
-- strict thread matches above, loose matches on Subject: below --
2012-09-25 8:38 [PATCH v2 memstick: support for legacy sony memsticks Maxim Levitsky
2012-09-25 8:38 ` [PATCH 1/2] scatterlist: add sg_nents Maxim Levitsky
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=20120926163851.GP16296@google.com \
--to=tj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=linux-kernel@vger.kernel.org \
--cc=maximlevitsky@gmail.com \
--cc=oakad@yahoo.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
Powered by JetHome