From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753269AbdK1Ved (ORCPT ); Tue, 28 Nov 2017 16:34:33 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:47088 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752823AbdK1Vdd (ORCPT ); Tue, 28 Nov 2017 16:33:33 -0500 From: Matthew Wilcox Cc: Matthew Wilcox , Chris Mi , Jiri Pirko , "David S . Miller" , Cong Wang , Jamal Hadi Salim , Daniel Borkmann , Eric Biggers , Lai Jiangshan , Tejun Heo , Rehas Sachdeva , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 10/17] cls_basic: Convert to use idr_alloc_u32 Date: Tue, 28 Nov 2017 13:33:05 -0800 Message-Id: <20171128213312.28983-11-willy@infradead.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171128213312.28983-1-willy@infradead.org> References: <20171128213312.28983-1-willy@infradead.org> To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matthew Wilcox Use the new helper which saves a temporary variable and a few lines of code. Signed-off-by: Matthew Wilcox --- net/sched/cls_basic.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/net/sched/cls_basic.c b/net/sched/cls_basic.c index 147700afcf31..529597c8c28c 100644 --- a/net/sched/cls_basic.c +++ b/net/sched/cls_basic.c @@ -182,7 +182,6 @@ static int basic_change(struct net *net, struct sk_buff *in_skb, struct nlattr *tb[TCA_BASIC_MAX + 1]; struct basic_filter *fold = (struct basic_filter *) *arg; struct basic_filter *fnew; - unsigned long idr_index; if (tca[TCA_OPTIONS] == NULL) return -EINVAL; @@ -205,21 +204,17 @@ static int basic_change(struct net *net, struct sk_buff *in_skb, if (err < 0) goto errout; - if (handle) { - fnew->handle = handle; - if (!fold) { - err = idr_alloc_ext(&head->handle_idr, fnew, &idr_index, - handle, handle + 1, GFP_KERNEL); - if (err) - goto errout; - } - } else { - err = idr_alloc_ext(&head->handle_idr, fnew, &idr_index, - 1, 0x7FFFFFFF, GFP_KERNEL); - if (err) - goto errout; - fnew->handle = idr_index; + if (!handle) { + handle = 1; + err = idr_alloc_u32(&head->handle_idr, fnew, &handle, + INT_MAX, GFP_KERNEL); + } else if (!fold) { + err = idr_alloc_u32(&head->handle_idr, fnew, &handle, + handle, GFP_KERNEL); } + if (err) + goto errout; + fnew->handle = handle; err = basic_set_parms(net, tp, fnew, base, tb, tca[TCA_RATE], ovr); if (err < 0) { -- 2.15.0