From: NeilBrown <neilb@suse.com>
To: Thomas Graf <tgraf@suug.ch>, Herbert Xu <herbert@gondor.apana.org.au>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/6] rhashtable: improve documentation for rhashtable_walk_peek()
Date: Tue, 27 Mar 2018 10:33:04 +1100 [thread overview]
Message-ID: <152210718418.11435.11573013181393548255.stgit@noble> (raw)
In-Reply-To: <152210688405.11435.13010923693146415942.stgit@noble>
The documentation for rhashtable_walk_peek() wrong. It claims to
return the *next* entry, whereas it in fact returns the *previous*
entry.
However if no entries have yet been returned - or if the iterator
was reset due to a resize event, then rhashtable_walk_peek()
*does* return the next entry, but also advances the iterator.
I suspect that this interface should be discarded and the one user
should be changed to not require it. Possibly this patch should be
seen as a first step in that conversation.
This patch mostly corrects the documentation, but does make a
small code change so that the documentation can be correct without
listing too many special cases. I don't think the one user will
be affected by the code change.
Signed-off-by: NeilBrown <neilb@suse.com>
---
lib/rhashtable.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index 3825c30aaa36..24a57ca494cb 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -853,13 +853,17 @@ void *rhashtable_walk_next(struct rhashtable_iter *iter)
EXPORT_SYMBOL_GPL(rhashtable_walk_next);
/**
- * rhashtable_walk_peek - Return the next object but don't advance the iterator
+ * rhashtable_walk_peek - Return the previously returned object without advancing the iterator
* @iter: Hash table iterator
*
- * Returns the next object or NULL when the end of the table is reached.
+ * Returns the last object returned, or NULL if no object has yet been returned.
+ * If the previously returned object has since been removed, then some other arbitrary
+ * object maybe returned, or possibly NULL will be returned. In that case, the
+ * iterator might be advanced.
*
* Returns -EAGAIN if resize event occurred. Note that the iterator
- * will rewind back to the beginning and you may continue to use it.
+ * will rewind back to the beginning and rhashtable_walk_next() should be
+ * used to get the next object.
*/
void *rhashtable_walk_peek(struct rhashtable_iter *iter)
{
@@ -880,7 +884,12 @@ void *rhashtable_walk_peek(struct rhashtable_iter *iter)
* the table hasn't changed.
*/
iter->skip--;
- }
+ } else
+ /* ->skip is only zero after rhashtable_walk_start()
+ * or when the iterator is reset. In this case there
+ * is no previous object to return.
+ */
+ return NULL;
return __rhashtable_walk_find_next(iter);
}
next prev parent reply other threads:[~2018-03-26 23:33 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-26 23:33 [PATCH 0/6] rhashtable: assorted fixes and enhancements NeilBrown
2018-03-26 23:33 ` NeilBrown [this message]
2018-03-27 10:55 ` [PATCH 1/6] rhashtable: improve documentation for rhashtable_walk_peek() Sergei Shtylyov
2018-03-27 15:30 ` Herbert Xu
2018-03-27 15:47 ` David Miller
2018-03-27 21:45 ` [PATCH 1/6 v2] " NeilBrown
2018-03-27 22:46 ` [PATCH 1/6] " Andreas Grünbacher
2018-03-28 0:49 ` NeilBrown
2018-03-26 23:33 ` [PATCH 6/6] rhashtable: allow element counting to be disabled NeilBrown
2018-03-26 23:33 ` [PATCH 2/6] rhashtable: remove outdated comments about grow_decision etc NeilBrown
2018-03-26 23:33 ` [PATCH 5/6] rhashtable: support guaranteed successful insertion NeilBrown
2018-03-27 15:56 ` Herbert Xu
2018-03-27 21:34 ` NeilBrown
2018-03-28 6:04 ` Herbert Xu
2018-03-28 7:04 ` NeilBrown
2018-03-28 7:27 ` Herbert Xu
2018-03-28 21:26 ` NeilBrown
2018-03-29 5:22 ` Herbert Xu
2018-04-06 3:11 ` NeilBrown
2018-04-06 4:13 ` Herbert Xu
2018-03-26 23:33 ` [PATCH 3/6] rhashtable: reset intr when rhashtable_walk_start sees new table NeilBrown
2018-03-27 15:47 ` Herbert Xu
2018-03-26 23:33 ` [PATCH 4/6] rhashtable: allow a walk of the hash table without missing objects NeilBrown
2018-03-27 15:49 ` David Miller
2018-03-27 15:54 ` Herbert Xu
2018-03-27 21:50 ` NeilBrown
2018-03-27 15:51 ` Herbert Xu
2018-03-27 21:54 ` NeilBrown
2018-03-28 6:07 ` Herbert Xu
2018-03-28 7:17 ` NeilBrown
2018-03-28 7:30 ` Herbert Xu
2018-03-28 21:34 ` NeilBrown
2018-03-29 1:13 ` NeilBrown
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=152210718418.11435.11573013181393548255.stgit@noble \
--to=neilb@suse.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=tgraf@suug.ch \
/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