From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jamal Hadi Salim Subject: [PATCH net-next 11/11] net: sched: cls_u32: simplify the hell out u32_delete() emptiness check Date: Sun, 7 Oct 2018 12:38:11 -0400 Message-ID: <20181007163811.18453-12-jhs@emojatatu.com> References: <20181007163811.18453-1-jhs@emojatatu.com> Cc: jiri@resnulli.us, xiyou.wangcong@gmail.com, viro@zeniv.linux.org.uk, netdev@vger.kernel.org, Jamal Hadi Salim To: davem@davemloft.net Return-path: Received: from mail-io1-f65.google.com ([209.85.166.65]:38199 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728058AbeJGXq1 (ORCPT ); Sun, 7 Oct 2018 19:46:27 -0400 Received: by mail-io1-f65.google.com with SMTP id n5-v6so3796633ioh.5 for ; Sun, 07 Oct 2018 09:38:38 -0700 (PDT) In-Reply-To: <20181007163811.18453-1-jhs@emojatatu.com> Sender: netdev-owner@vger.kernel.org List-ID: From: Al Viro Now that we have the knode count, we can instantly check if any hnodes are non-empty. And that kills the check for extra references to root hnode - those could happen only if there was a knode to carry such a link. Signed-off-by: Al Viro Signed-off-by: Jamal Hadi Salim --- net/sched/cls_u32.c | 48 +----------------------------------------------- 1 file changed, 1 insertion(+), 47 deletions(-) diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index 61593bee08db..ac79a40a0392 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -627,17 +627,6 @@ static int u32_destroy_hnode(struct tcf_proto *tp, struct tc_u_hnode *ht, return -ENOENT; } -static bool ht_empty(struct tc_u_hnode *ht) -{ - unsigned int h; - - for (h = 0; h <= ht->divisor; h++) - if (rcu_access_pointer(ht->ht[h])) - return false; - - return true; -} - static void u32_destroy(struct tcf_proto *tp, struct netlink_ext_ack *extack) { struct tc_u_common *tp_c = tp->data; @@ -675,13 +664,9 @@ static int u32_delete(struct tcf_proto *tp, void *arg, bool *last, struct netlink_ext_ack *extack) { struct tc_u_hnode *ht = arg; - struct tc_u_hnode *root_ht = rtnl_dereference(tp->root); struct tc_u_common *tp_c = tp->data; int ret = 0; - if (ht == NULL) - goto out; - if (TC_U32_KEY(ht->handle)) { u32_remove_hw_knode(tp, (struct tc_u_knode *)ht, extack); ret = u32_delete_key(tp, (struct tc_u_knode *)ht); @@ -702,38 +687,7 @@ static int u32_delete(struct tcf_proto *tp, void *arg, bool *last, } out: - *last = true; - if (root_ht) { - if (root_ht->refcnt > 1) { - *last = false; - goto ret; - } - if (root_ht->refcnt == 1) { - if (!ht_empty(root_ht)) { - *last = false; - goto ret; - } - } - } - - if (tp_c->refcnt > 1) { - *last = false; - goto ret; - } - - if (tp_c->refcnt == 1) { - struct tc_u_hnode *ht; - - for (ht = rtnl_dereference(tp_c->hlist); - ht; - ht = rtnl_dereference(ht->next)) - if (!ht_empty(ht)) { - *last = false; - break; - } - } - -ret: + *last = tp_c->refcnt == 1 && tp_c->knodes == 0; return ret; } -- 2.11.0