Skip to content

Commit 679972f

Browse files
apconoleummakynes
authored andcommitted
netfilter: convert while loops to for loops
This is to facilitate converting from a singly-linked list to an array of elements. Signed-off-by: Aaron Conole <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent d415b9e commit 679972f

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

net/bridge/br_netfilter_hooks.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,10 +1008,10 @@ int br_nf_hook_thresh(unsigned int hook, struct net *net,
10081008
struct nf_hook_state state;
10091009
int ret;
10101010

1011-
elem = rcu_dereference(net->nf.hooks[NFPROTO_BRIDGE][hook]);
1012-
1013-
while (elem && (nf_hook_entry_priority(elem) <= NF_BR_PRI_BRNF))
1014-
elem = rcu_dereference(elem->next);
1011+
for (elem = rcu_dereference(net->nf.hooks[NFPROTO_BRIDGE][hook]);
1012+
elem && nf_hook_entry_priority(elem) <= NF_BR_PRI_BRNF;
1013+
elem = rcu_dereference(elem->next))
1014+
;
10151015

10161016
if (!elem)
10171017
return okfn(net, sk, skb);

net/netfilter/core.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,9 @@ int nf_register_net_hook(struct net *net, const struct nf_hook_ops *reg)
107107
mutex_lock(&nf_hook_mutex);
108108

109109
/* Find the spot in the list */
110-
while ((p = nf_entry_dereference(*pp)) != NULL) {
110+
for (; (p = nf_entry_dereference(*pp)) != NULL; pp = &p->next) {
111111
if (reg->priority < nf_hook_entry_priority(p))
112112
break;
113-
pp = &p->next;
114113
}
115114
rcu_assign_pointer(entry->next, p);
116115
rcu_assign_pointer(*pp, entry);
@@ -137,12 +136,11 @@ void nf_unregister_net_hook(struct net *net, const struct nf_hook_ops *reg)
137136
return;
138137

139138
mutex_lock(&nf_hook_mutex);
140-
while ((p = nf_entry_dereference(*pp)) != NULL) {
139+
for (; (p = nf_entry_dereference(*pp)) != NULL; pp = &p->next) {
141140
if (nf_hook_entry_ops(p) == reg) {
142141
rcu_assign_pointer(*pp, p->next);
143142
break;
144143
}
145-
pp = &p->next;
146144
}
147145
mutex_unlock(&nf_hook_mutex);
148146
if (!p) {

0 commit comments

Comments
 (0)