netfilter: convert while loops to for loops
authorAaron Conole <aconole@bytheb.org>
Tue, 15 Nov 2016 22:48:46 +0000 (17:48 -0500)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 6 Dec 2016 20:42:16 +0000 (21:42 +0100)
This is to facilitate converting from a singly-linked list to an array
of elements.

Signed-off-by: Aaron Conole <aconole@bytheb.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/bridge/br_netfilter_hooks.c
net/netfilter/core.c

index adad2eed29e68b35f5cae8737fac30f1f195c090..b12501a77f18f6df4f22572ea8885a929d458e0b 100644 (file)
@@ -1008,10 +1008,10 @@ int br_nf_hook_thresh(unsigned int hook, struct net *net,
        struct nf_hook_state state;
        int ret;
 
-       elem = rcu_dereference(net->nf.hooks[NFPROTO_BRIDGE][hook]);
-
-       while (elem && (nf_hook_entry_priority(elem) <= NF_BR_PRI_BRNF))
-               elem = rcu_dereference(elem->next);
+       for (elem = rcu_dereference(net->nf.hooks[NFPROTO_BRIDGE][hook]);
+            elem && nf_hook_entry_priority(elem) <= NF_BR_PRI_BRNF;
+            elem = rcu_dereference(elem->next))
+               ;
 
        if (!elem)
                return okfn(net, sk, skb);
index 2bb46e2d8d30d1d4b9d2a6aafa0906ccbad486ab..ce6adfae521a1cdf5f479984ada3699dd7f3ddaa 100644 (file)
@@ -107,10 +107,9 @@ int nf_register_net_hook(struct net *net, const struct nf_hook_ops *reg)
        mutex_lock(&nf_hook_mutex);
 
        /* Find the spot in the list */
-       while ((p = nf_entry_dereference(*pp)) != NULL) {
+       for (; (p = nf_entry_dereference(*pp)) != NULL; pp = &p->next) {
                if (reg->priority < nf_hook_entry_priority(p))
                        break;
-               pp = &p->next;
        }
        rcu_assign_pointer(entry->next, p);
        rcu_assign_pointer(*pp, entry);
@@ -137,12 +136,11 @@ void nf_unregister_net_hook(struct net *net, const struct nf_hook_ops *reg)
                return;
 
        mutex_lock(&nf_hook_mutex);
-       while ((p = nf_entry_dereference(*pp)) != NULL) {
+       for (; (p = nf_entry_dereference(*pp)) != NULL; pp = &p->next) {
                if (nf_hook_entry_ops(p) == reg) {
                        rcu_assign_pointer(*pp, p->next);
                        break;
                }
-               pp = &p->next;
        }
        mutex_unlock(&nf_hook_mutex);
        if (!p) {