Skip to content

Commit 21e289c

Browse files
tititiou36Ulrich Hecht
authored andcommitted
macvlan: Use 'hash' iterators to simplify code
[ Upstream commit bb23ffa1015cb57e0c9ec3c6135275b38d66a780 ] Use 'hash_for_each_rcu' and 'hash_for_each_safe' instead of hand writing them. This saves some lines of code, reduce indentation and improve readability. Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Signed-off-by: David S. Miller <davem@davemloft.net> Stable-dep-of: 7470a7a63dc1 ("macvlan: fix possible UAF in macvlan_forward_source()") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Ulrich Hecht <uli@kernel.org>
1 parent 981eb73 commit 21e289c

1 file changed

Lines changed: 18 additions & 27 deletions

File tree

drivers/net/macvlan.c

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -273,25 +273,22 @@ static void macvlan_broadcast(struct sk_buff *skb,
273273
if (skb->protocol == htons(ETH_P_PAUSE))
274274
return;
275275

276-
for (i = 0; i < MACVLAN_HASH_SIZE; i++) {
277-
hlist_for_each_entry_rcu(vlan, &port->vlan_hash[i], hlist) {
278-
if (vlan->dev == src || !(vlan->mode & mode))
279-
continue;
276+
hash_for_each_rcu(port->vlan_hash, i, vlan, hlist) {
277+
if (vlan->dev == src || !(vlan->mode & mode))
278+
continue;
280279

281-
hash = mc_hash(vlan, eth->h_dest);
282-
if (!test_bit(hash, vlan->mc_filter))
283-
continue;
280+
hash = mc_hash(vlan, eth->h_dest);
281+
if (!test_bit(hash, vlan->mc_filter))
282+
continue;
284283

285-
err = NET_RX_DROP;
286-
nskb = skb_clone(skb, GFP_ATOMIC);
287-
if (likely(nskb))
288-
err = macvlan_broadcast_one(
289-
nskb, vlan, eth,
284+
err = NET_RX_DROP;
285+
nskb = skb_clone(skb, GFP_ATOMIC);
286+
if (likely(nskb))
287+
err = macvlan_broadcast_one(nskb, vlan, eth,
290288
mode == MACVLAN_MODE_BRIDGE) ?:
291-
netif_rx_ni(nskb);
292-
macvlan_count_rx(vlan, skb->len + ETH_HLEN,
293-
err == NET_RX_SUCCESS, true);
294-
}
289+
netif_rx_ni(nskb);
290+
macvlan_count_rx(vlan, skb->len + ETH_HLEN,
291+
err == NET_RX_SUCCESS, true);
295292
}
296293
}
297294

@@ -381,20 +378,14 @@ static void macvlan_broadcast_enqueue(struct macvlan_port *port,
381378
static void macvlan_flush_sources(struct macvlan_port *port,
382379
struct macvlan_dev *vlan)
383380
{
381+
struct macvlan_source_entry *entry;
382+
struct hlist_node *next;
384383
int i;
385384

386-
for (i = 0; i < MACVLAN_HASH_SIZE; i++) {
387-
struct hlist_node *h, *n;
388-
389-
hlist_for_each_safe(h, n, &port->vlan_source_hash[i]) {
390-
struct macvlan_source_entry *entry;
385+
hash_for_each_safe(port->vlan_source_hash, i, next, entry, hlist)
386+
if (entry->vlan == vlan)
387+
macvlan_hash_del_source(entry);
391388

392-
entry = hlist_entry(h, struct macvlan_source_entry,
393-
hlist);
394-
if (entry->vlan == vlan)
395-
macvlan_hash_del_source(entry);
396-
}
397-
}
398389
vlan->macaddr_count = 0;
399390
}
400391

0 commit comments

Comments
 (0)