From: Matthew Wilcox <willy@infradead.org>
To: willy@infradead.org, netdev@vger.kernel.org
Cc: Matthew Wilcox <mawilcox@microsoft.com>
Subject: [PATCH v2 09/17] net sched actions: Convert to use idr_alloc_u32
Date: Wed, 29 Nov 2017 12:19:14 -0800 [thread overview]
Message-ID: <20171129201922.24370-10-willy@infradead.org> (raw)
In-Reply-To: <20171129201922.24370-1-willy@infradead.org>
From: Matthew Wilcox <mawilcox@microsoft.com>
Use the new helper. Also untangle the error path, and in so doing
noticed that estimator generator failure would lead to us leaking an
ID. Fix that bug.
Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
---
net/sched/act_api.c | 60 ++++++++++++++++++++++-------------------------------
1 file changed, 25 insertions(+), 35 deletions(-)
diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index efb90b8a3bf0..156302c110af 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -274,7 +274,6 @@ int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est,
struct tcf_idrinfo *idrinfo = tn->idrinfo;
struct idr *idr = &idrinfo->action_idr;
int err = -ENOMEM;
- unsigned long idr_index;
if (unlikely(!p))
return -ENOMEM;
@@ -284,45 +283,28 @@ int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est,
if (cpustats) {
p->cpu_bstats = netdev_alloc_pcpu_stats(struct gnet_stats_basic_cpu);
- if (!p->cpu_bstats) {
-err1:
- kfree(p);
- return err;
- }
- p->cpu_qstats = alloc_percpu(struct gnet_stats_queue);
- if (!p->cpu_qstats) {
-err2:
- free_percpu(p->cpu_bstats);
+ if (!p->cpu_bstats)
goto err1;
- }
+ p->cpu_qstats = alloc_percpu(struct gnet_stats_queue);
+ if (!p->cpu_qstats)
+ goto err2;
}
spin_lock_init(&p->tcfa_lock);
+ idr_preload(GFP_KERNEL);
+ spin_lock_bh(&idrinfo->lock);
/* user doesn't specify an index */
if (!index) {
- idr_preload(GFP_KERNEL);
- spin_lock_bh(&idrinfo->lock);
- err = idr_alloc_ext(idr, NULL, &idr_index, 1, 0,
- GFP_ATOMIC);
- spin_unlock_bh(&idrinfo->lock);
- idr_preload_end();
- if (err) {
-err3:
- free_percpu(p->cpu_qstats);
- goto err2;
- }
- p->tcfa_index = idr_index;
+ index = 1;
+ err = idr_alloc_u32(idr, NULL, &index, UINT_MAX, GFP_ATOMIC);
} else {
- idr_preload(GFP_KERNEL);
- spin_lock_bh(&idrinfo->lock);
- err = idr_alloc_ext(idr, NULL, NULL, index, index + 1,
- GFP_ATOMIC);
- spin_unlock_bh(&idrinfo->lock);
- idr_preload_end();
- if (err)
- goto err3;
- p->tcfa_index = index;
+ err = idr_alloc_u32(idr, NULL, &index, index, GFP_ATOMIC);
}
+ spin_unlock_bh(&idrinfo->lock);
+ idr_preload_end();
+ if (err)
+ goto err3;
+ p->tcfa_index = index;
p->tcfa_tm.install = jiffies;
p->tcfa_tm.lastuse = jiffies;
p->tcfa_tm.firstuse = 0;
@@ -330,9 +312,8 @@ int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est,
err = gen_new_estimator(&p->tcfa_bstats, p->cpu_bstats,
&p->tcfa_rate_est,
&p->tcfa_lock, NULL, est);
- if (err) {
- goto err3;
- }
+ if (err)
+ goto err4;
}
p->idrinfo = idrinfo;
@@ -340,6 +321,15 @@ int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est,
INIT_LIST_HEAD(&p->list);
*a = p;
return 0;
+err4:
+ idr_remove(idr, index);
+err3:
+ free_percpu(p->cpu_qstats);
+err2:
+ free_percpu(p->cpu_bstats);
+err1:
+ kfree(p);
+ return err;
}
EXPORT_SYMBOL(tcf_idr_create);
--
2.15.0
next prev parent reply other threads:[~2017-11-29 20:19 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-29 20:19 [PATCH v2 00/17] IDR changes for v4.15-rc1 Matthew Wilcox
2017-11-29 20:19 ` [PATCH v2 01/17] idr: Fix build Matthew Wilcox
2017-11-29 20:19 ` [PATCH v2 02/17] radix tree test suite: Remove ARRAY_SIZE Matthew Wilcox
2017-11-29 20:19 ` [PATCH v2 03/17] idr test suite: Fix ida_test_random() Matthew Wilcox
2017-11-29 20:19 ` [PATCH v2 04/17] IDR test suite: Check handling negative end correctly Matthew Wilcox
2017-11-29 20:19 ` [PATCH v2 05/17] idr: Delete idr_remove_ext function Matthew Wilcox
2017-11-29 20:19 ` [PATCH v2 06/17] idr: Delete idr_replace_ext function Matthew Wilcox
2017-11-29 20:19 ` [PATCH v2 07/17] idr: Delete idr_find_ext function Matthew Wilcox
2017-11-29 20:19 ` [PATCH v2 08/17] idr: Add idr_alloc_u32 helper Matthew Wilcox
2017-11-29 20:19 ` Matthew Wilcox [this message]
2017-11-29 20:19 ` [PATCH v2 10/17] cls_basic: Convert to use idr_alloc_u32 Matthew Wilcox
2017-11-29 20:19 ` [PATCH v2 11/17] cls_bpf: " Matthew Wilcox
2017-11-29 20:19 ` [PATCH v2 12/17] cls_flower: Convert to idr_alloc_u32 Matthew Wilcox
2017-11-29 20:19 ` [PATCH v2 13/17] cls_u32: Reinstate cyclic allocation Matthew Wilcox
2017-11-29 20:19 ` [PATCH v2 14/17] cls_u32: Convert to idr_alloc_u32 Matthew Wilcox
2017-11-29 20:19 ` [PATCH v2 15/17] idr: Rename idr_alloc_ext to idr_alloc_ul Matthew Wilcox
2017-11-29 20:19 ` [PATCH v2 16/17] idr: Rename idr_for_each_entry_ext Matthew Wilcox
2017-11-29 20:19 ` [PATCH v2 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=20171129201922.24370-10-willy@infradead.org \
--to=willy@infradead.org \
--cc=mawilcox@microsoft.com \
--cc=netdev@vger.kernel.org \
/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).