From: Matthew Wilcox <willy@infradead.org>
To: unlisted-recipients:; (no To-header on input)
Cc: Matthew Wilcox <mawilcox@microsoft.com>,
Chris Mi <chrism@mellanox.com>, Jiri Pirko <jiri@mellanox.com>,
"David S . Miller" <davem@davemloft.net>,
Cong Wang <xiyou.wangcong@gmail.com>,
Jamal Hadi Salim <jhs@mojatatu.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Eric Biggers <ebiggers@google.com>,
Lai Jiangshan <laijs@cn.fujitsu.com>, Tejun Heo <tj@kernel.org>,
Rehas Sachdeva <aquannie@gmail.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 16/17] idr: Rename idr_for_each_entry_ext
Date: Tue, 28 Nov 2017 13:33:11 -0800 [thread overview]
Message-ID: <20171128213312.28983-17-willy@infradead.org> (raw)
In-Reply-To: <20171128213312.28983-1-willy@infradead.org>
From: Matthew Wilcox <mawilcox@microsoft.com>
Match idr_alloc_ul with idr_get_next_ul and idr_for_each_entry_ul.
Also add kernel-doc.
Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
---
include/linux/idr.h | 17 ++++++++++++++---
lib/idr.c | 20 +++++++++++++++-----
net/sched/act_api.c | 6 +++---
3 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/include/linux/idr.h b/include/linux/idr.h
index 344380fd0887..91d27a9bcdf4 100644
--- a/include/linux/idr.h
+++ b/include/linux/idr.h
@@ -88,7 +88,7 @@ int idr_alloc_cyclic(struct idr *, void *entry, int start, int end, gfp_t);
int idr_for_each(const struct idr *,
int (*fn)(int id, void *p, void *data), void *data);
void *idr_get_next(struct idr *, int *nextid);
-void *idr_get_next_ext(struct idr *idr, unsigned long *nextid);
+void *idr_get_next_ul(struct idr *, unsigned long *nextid);
void *idr_replace(struct idr *, void *, unsigned long id);
void idr_destroy(struct idr *);
@@ -178,8 +178,19 @@ static inline void *idr_find(const struct idr *idr, unsigned long id)
*/
#define idr_for_each_entry(idr, entry, id) \
for (id = 0; ((entry) = idr_get_next(idr, &(id))) != NULL; ++id)
-#define idr_for_each_entry_ext(idr, entry, id) \
- for (id = 0; ((entry) = idr_get_next_ext(idr, &(id))) != NULL; ++id)
+
+/**
+ * idr_for_each_entry_ul() - iterate over an IDR's elements of a given type.
+ * @idr: IDR handle.
+ * @entry: The type * to use as cursor.
+ * @id: Entry ID.
+ *
+ * @entry and @id do not need to be initialized before the loop, and
+ * after normal terminatinon @entry is left with the value NULL. This
+ * is convenient for a "not found" value.
+ */
+#define idr_for_each_entry_ul(idr, entry, id) \
+ for (id = 0; ((entry) = idr_get_next_ul(idr, &(id))) != NULL; ++id)
/**
* idr_for_each_entry_continue - continue iteration over an idr's elements of a given type
diff --git a/lib/idr.c b/lib/idr.c
index 103afb97b4bd..772a24513d1e 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -155,9 +155,9 @@ int idr_for_each(const struct idr *idr,
EXPORT_SYMBOL(idr_for_each);
/**
- * idr_get_next - Find next populated entry
- * @idr: idr handle
- * @nextid: Pointer to lowest possible ID to return
+ * idr_get_next() - Find next populated entry.
+ * @idr: IDR handle.
+ * @nextid: Pointer to lowest possible ID to return.
*
* Returns the next populated entry in the tree with an ID greater than
* or equal to the value pointed to by @nextid. On exit, @nextid is updated
@@ -178,7 +178,17 @@ void *idr_get_next(struct idr *idr, int *nextid)
}
EXPORT_SYMBOL(idr_get_next);
-void *idr_get_next_ext(struct idr *idr, unsigned long *nextid)
+/**
+ * idr_get_next_ul() - Find next populated entry.
+ * @idr: IDR handle.
+ * @nextid: Pointer to lowest possible ID to return.
+ *
+ * Returns the next populated entry in the tree with an ID greater than
+ * or equal to the value pointed to by @nextid. On exit, @nextid is updated
+ * to the ID of the found value. To use in a loop, the value pointed to by
+ * nextid must be incremented by the user.
+ */
+void *idr_get_next_ul(struct idr *idr, unsigned long *nextid)
{
struct radix_tree_iter iter;
void __rcu **slot;
@@ -190,7 +200,7 @@ void *idr_get_next_ext(struct idr *idr, unsigned long *nextid)
*nextid = iter.index;
return rcu_dereference_raw(*slot);
}
-EXPORT_SYMBOL(idr_get_next_ext);
+EXPORT_SYMBOL(idr_get_next_ul);
/**
* idr_replace - replace pointer for given id
diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index 156302c110af..4133d91b7029 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -124,7 +124,7 @@ static int tcf_dump_walker(struct tcf_idrinfo *idrinfo, struct sk_buff *skb,
s_i = cb->args[0];
- idr_for_each_entry_ext(idr, p, id) {
+ idr_for_each_entry_ul(idr, p, id) {
index++;
if (index < s_i)
continue;
@@ -181,7 +181,7 @@ static int tcf_del_walker(struct tcf_idrinfo *idrinfo, struct sk_buff *skb,
if (nla_put_string(skb, TCA_KIND, ops->kind))
goto nla_put_failure;
- idr_for_each_entry_ext(idr, p, id) {
+ idr_for_each_entry_ul(idr, p, id) {
ret = __tcf_idr_release(p, false, true);
if (ret == ACT_P_DELETED) {
module_put(ops->owner);
@@ -351,7 +351,7 @@ void tcf_idrinfo_destroy(const struct tc_action_ops *ops,
int ret;
unsigned long id = 1;
- idr_for_each_entry_ext(idr, p, id) {
+ idr_for_each_entry_ul(idr, p, id) {
ret = __tcf_idr_release(p, false, true);
if (ret == ACT_P_DELETED)
module_put(ops->owner);
--
2.15.0
next prev parent reply other threads:[~2017-11-28 21:40 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-28 21:32 [PATCH 00/17] IDR patches for 4.15 Matthew Wilcox
2017-11-28 21:32 ` [PATCH 01/17] idr: Fix build Matthew Wilcox
2017-11-28 21:32 ` [PATCH 02/17] radix tree test suite: Remove ARRAY_SIZE Matthew Wilcox
2017-11-28 21:32 ` [PATCH 03/17] idr test suite: Fix ida_test_random() Matthew Wilcox
2017-11-28 21:32 ` [PATCH 04/17] IDR test suite: Check handling negative end correctly Matthew Wilcox
2017-11-28 21:33 ` [PATCH 05/17] idr: Delete idr_remove_ext function Matthew Wilcox
2017-11-28 21:33 ` [PATCH 06/17] idr: Delete idr_replace_ext function Matthew Wilcox
2017-11-28 21:33 ` [PATCH 07/17] idr: Delete idr_find_ext function Matthew Wilcox
2017-11-28 21:33 ` [PATCH 08/17] idr: Add idr_alloc_u32 helper Matthew Wilcox
2017-11-28 21:33 ` [PATCH 09/17] net sched actions: Convert to use idr_alloc_u32 Matthew Wilcox
2017-11-28 21:33 ` [PATCH 10/17] cls_basic: " Matthew Wilcox
2017-11-28 21:33 ` [PATCH 11/17] cls_bpf: " Matthew Wilcox
2017-11-29 1:08 ` Jakub Kicinski
2017-11-29 16:29 ` Matthew Wilcox
2017-11-29 16:35 ` David Miller
2017-11-28 21:33 ` [PATCH 12/17] cls_flower: Convert to idr_alloc_u32 Matthew Wilcox
2017-11-28 21:33 ` [PATCH 13/17] cls_u32: Reinstate cyclic allocation Matthew Wilcox
2017-11-28 21:33 ` [PATCH 14/17] cls_u32: Convert to idr_alloc_u32 Matthew Wilcox
2017-11-28 21:33 ` [PATCH 15/17] idr: Rename idr_alloc_ext to idr_alloc_ul Matthew Wilcox
2017-11-28 21:33 ` Matthew Wilcox [this message]
2017-11-28 21:33 ` [PATCH 17/17] idr: Warn if old iterators see large IDs Matthew Wilcox
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=20171128213312.28983-17-willy@infradead.org \
--to=willy@infradead.org \
--cc=aquannie@gmail.com \
--cc=chrism@mellanox.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=ebiggers@google.com \
--cc=jhs@mojatatu.com \
--cc=jiri@mellanox.com \
--cc=laijs@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mawilcox@microsoft.com \
--cc=netdev@vger.kernel.org \
--cc=tj@kernel.org \
--cc=xiyou.wangcong@gmail.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;
as well as URLs for NNTP newsgroup(s).