From patchwork Wed Nov 29 20:19:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthew Wilcox (Oracle)" X-Patchwork-Id: 842721 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="bUH8Vnq1"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynBjb5LDBz9s4s for ; Thu, 30 Nov 2017 07:20:19 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752802AbdK2UUE (ORCPT ); Wed, 29 Nov 2017 15:20:04 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:54730 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752556AbdK2UTh (ORCPT ); Wed, 29 Nov 2017 15:19:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=OQn3Guui1MAselCC5zqxCNKp57if5GQ2N6XRc5zq0F8=; b=bUH8Vnq1bOc+krTtSuVLAUKXj m5kx8QjIVE9AOLjJFxCeeQsEAr/UM4rNadAiDMpNEW4vHjY469LZ9aWwqjGanS2C7efCJnegndshA 7AtikeDw7/LFSVHaZMxAKArc9tucekJUAOtLQM3wxtu47XrpfKerToQqBrlfYFf2cUykVUFE5XsVV yea60vgrKRwm38G3ayoSBelXeLVcAUeWgjbrQh+HIgPlf3a5p5ToJl4jhAeDbQ4+7nuk8uFJaeDul UsJzMfT6eGwXTTPJbLka7aK3ZERMy0MTo9thek4ZKbc8yR8yfejn89ClVlN7VjNqeTlURedQ5LmoA todo3v0cA==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eK8pV-0006Ok-2p; Wed, 29 Nov 2017 20:19:37 +0000 From: Matthew Wilcox To: willy@infradead.org, netdev@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH v2 16/17] idr: Rename idr_for_each_entry_ext Date: Wed, 29 Nov 2017 12:19:21 -0800 Message-Id: <20171129201922.24370-17-willy@infradead.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171129201922.24370-1-willy@infradead.org> References: <20171129201922.24370-1-willy@infradead.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Matthew Wilcox Match idr_alloc_ul with idr_get_next_ul and idr_for_each_entry_ul. Also add kernel-doc. Signed-off-by: Matthew Wilcox --- 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);