From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matthew Wilcox Subject: [PATCH v2 11/17] cls_bpf: Convert to use idr_alloc_u32 Date: Wed, 29 Nov 2017 12:19:16 -0800 Message-ID: <20171129201922.24370-12-willy@infradead.org> References: <20171129201922.24370-1-willy@infradead.org> Cc: Matthew Wilcox To: willy@infradead.org, netdev@vger.kernel.org Return-path: Received: from bombadil.infradead.org ([65.50.211.133]:50771 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752216AbdK2UTg (ORCPT ); Wed, 29 Nov 2017 15:19:36 -0500 In-Reply-To: <20171129201922.24370-1-willy@infradead.org> Sender: netdev-owner@vger.kernel.org List-ID: From: Matthew Wilcox Use the new helper. This has a modest reduction in both lines of code and compiled code size. Signed-off-by: Matthew Wilcox --- net/sched/cls_bpf.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/net/sched/cls_bpf.c b/net/sched/cls_bpf.c index 1660fc8294ef..db1dd4de7d6a 100644 --- a/net/sched/cls_bpf.c +++ b/net/sched/cls_bpf.c @@ -472,7 +472,6 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb, struct cls_bpf_prog *oldprog = *arg; struct nlattr *tb[TCA_BPF_MAX + 1]; struct cls_bpf_prog *prog; - unsigned long idr_index; int ret; if (tca[TCA_OPTIONS] == NULL) @@ -499,21 +498,18 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb, } if (handle == 0) { - ret = idr_alloc_ext(&head->handle_idr, prog, &idr_index, - 1, 0x7FFFFFFF, GFP_KERNEL); - if (ret) - goto errout; - prog->handle = idr_index; - } else { - if (!oldprog) { - ret = idr_alloc_ext(&head->handle_idr, prog, &idr_index, - handle, handle + 1, GFP_KERNEL); - if (ret) - goto errout; - } - prog->handle = handle; + handle = 1; + ret = idr_alloc_u32(&head->handle_idr, prog, &handle, + INT_MAX, GFP_KERNEL); + } else if (!oldprog) { + ret = idr_alloc_u32(&head->handle_idr, prog, &handle, + handle, GFP_KERNEL); } + if (ret) + goto errout; + prog->handle = handle; + ret = cls_bpf_set_parms(net, tp, prog, base, tb, tca[TCA_RATE], ovr); if (ret < 0) goto errout_idr; -- 2.15.0