From patchwork Wed Nov 29 20:19:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 842726 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="ThHkPOt3"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynBk10DjLz9s4s for ; Thu, 30 Nov 2017 07:20:41 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752841AbdK2UUe (ORCPT ); Wed, 29 Nov 2017 15:20:34 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:41810 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752361AbdK2UTh (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=hI8QRXPX2uRnUSCymmfo3DEcRKLeRLV3RFLCMUJv2pM=; b=ThHkPOt3BFuT63fzVWJ+PVeOi hrMi0OGkIEU3h+K/BWaGuo7/AtDRPI9CfCG4u2mJD0RWiPaMeEnopBR1m+DvwCAj+Mw1FpKRrVNkg KiZi29rtwiWYFIMMRjBxkKGJeJbFqpqOzObG5BX2r5+1Wg+0aih8OA1M9MFi7j9UqscDDpeSUWLdu ctg88lFUk1oyVsUB/RuM8b3AU4mAdThbUyKPrDTDNClOo11JloVWkJFt59JyIFvNWlr4uEwqjC2yA 56ipNrJqZQR1vpNntgZ76kWm3K/Pkz/hYwLH6foonsw6OqjlR43kg13oTOH0NmyHo2PVqdoUrTLlS kCpV1eYBg==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eK8pU-0006OF-Nt; Wed, 29 Nov 2017 20:19:36 +0000 From: Matthew Wilcox To: willy@infradead.org, netdev@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH v2 12/17] cls_flower: Convert to idr_alloc_u32 Date: Wed, 29 Nov 2017 12:19:17 -0800 Message-Id: <20171129201922.24370-13-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 Use the new helper which saves a temporary variable and a few lines of code. Signed-off-by: Matthew Wilcox --- net/sched/cls_flower.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c index ec0dc92f6104..adee3cf30bb3 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -858,7 +858,6 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, struct cls_fl_filter *fnew; struct nlattr **tb; struct fl_flow_mask mask = {}; - unsigned long idr_index; int err; if (!tca[TCA_OPTIONS]) @@ -889,21 +888,17 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, goto errout; if (!handle) { - err = idr_alloc_ext(&head->handle_idr, fnew, &idr_index, - 1, 0x80000000, GFP_KERNEL); - if (err) - goto errout; - fnew->handle = idr_index; - } - - /* user specifies a handle and it doesn't exist */ - if (handle && !fold) { - err = idr_alloc_ext(&head->handle_idr, fnew, &idr_index, - handle, handle + 1, GFP_KERNEL); - if (err) - goto errout; - fnew->handle = idr_index; + handle = 1; + err = idr_alloc_u32(&head->handle_idr, fnew, &handle, + INT_MAX, GFP_KERNEL); + } else if (!fold) { + /* user specifies a handle and it doesn't exist */ + err = idr_alloc_u32(&head->handle_idr, fnew, &handle, + handle, GFP_KERNEL); } + if (err) + goto errout; + fnew->handle = handle; if (tb[TCA_FLOWER_FLAGS]) { fnew->flags = nla_get_u32(tb[TCA_FLOWER_FLAGS]); @@ -957,7 +952,6 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, *arg = fnew; if (fold) { - fnew->handle = handle; idr_replace(&head->handle_idr, fnew, fnew->handle); list_replace_rcu(&fold->list, &fnew->list); tcf_unbind_filter(tp, &fold->res);