Skip to contentSkip to conversation

bridge: slight optimization of addr compare

PATCH Superseded Ding Tianhong 2 participants 3 messages Dec 23, 2013

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 12/21 bridge: slight optimization of addr compare

Use the recently added and possibly more efficient ether_addr_equal_unaligned to instead of memcmp.

---
 net/bridge/br_stp_if.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/bridge/br_stp_if.c +1 -1
index 656a6f3..04217d1 100644
@@ -229,7 +229,7 @@ bool br_stp_recalculate_bridge_id(struct net_bridge *br)
 
 	list_for_each_entry(p, &br->port_list, list) {
 		if (addr == br_mac_zero ||
-		    memcmp(p->dev->dev_addr, addr, ETH_ALEN) < 0)
+		    !ether_addr_equal_unaligned(p->dev->dev_addr, addr) < 0)
 			addr = p->dev->dev_addr;
 
 	}
Signature · 1 line
1.8.0
#1 lore raw
Quoted 18 lines · Ding Tianhong

Use the recently added and possibly more efficient ether_addr_equal_unaligned to instead of memcmp.

---
 net/bridge/br_stp_if.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/bridge/br_stp_if.c +0 -0
index 656a6f3..04217d1 100644

net/bridge/br_stp_if.c bool br_stp_recalculate_bridge_id(struct net_bridge *br) · line 235

Quoted 8 lines
net/bridge/br_stp_if.c +1 -1
@@ -229,7 +229,7 @@ bool br_stp_recalculate_bridge_id(struct net_bridge *br)
 
 	list_for_each_entry(p, &br->port_list, list) {
 		if (addr == br_mac_zero ||
-		    memcmp(p->dev->dev_addr, addr, ETH_ALEN) < 0)
+		    !ether_addr_equal_unaligned(p->dev->dev_addr, addr) < 0)
 			addr = p->dev->dev_addr;
 
 	}

We cannot do this change.
!ether_addr_equal() isn't identical to memcmp().
memcmp() can return negative value but ether_addr_equal() cannot. br_stp_recalculate_bridge_id() is searching the smallest address among its ports. This change breaks it.

Thanks,
Toshiaki Makita

#2 lore raw
Quoted 34 lines · Toshiaki Makita
Quoted 18 lines · Ding Tianhong

Use the recently added and possibly more efficient ether_addr_equal_unaligned to instead of memcmp.

---
 net/bridge/br_stp_if.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/bridge/br_stp_if.c +0 -0
index 656a6f3..04217d1 100644

net/bridge/br_stp_if.c bool br_stp_recalculate_bridge_id(struct net_bridge *br) · line 235

Quoted 8 lines
net/bridge/br_stp_if.c +1 -1
@@ -229,7 +229,7 @@ bool br_stp_recalculate_bridge_id(struct net_bridge *br)
 
 	list_for_each_entry(p, &br->port_list, list) {
 		if (addr == br_mac_zero ||
-		    memcmp(p->dev->dev_addr, addr, ETH_ALEN) < 0)
+		    !ether_addr_equal_unaligned(p->dev->dev_addr, addr) < 0)
 			addr = p->dev->dev_addr;
 
 	}

We cannot do this change.
!ether_addr_equal() isn't identical to memcmp().
memcmp() can return negative value but ether_addr_equal() cannot. br_stp_recalculate_bridge_id() is searching the smallest address among its ports. This change breaks it.

Quoted 2 lines

Thanks,
Toshiaki Makita

Yes, I miss it, the negative value is useful here, thanks for point out.

Regards
Ding

Quoted 3 lines