Skip to contentSkip to conversation

batman-adv: slight optimization of addr compare

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

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 9/21 batman-adv: slight optimization of addr compare

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

---
 net/batman-adv/originator.c        | 2 +-
 net/batman-adv/translation-table.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
net/batman-adv/originator.c +1 -1
index 8ab1434..0490a26 100644
@@ -41,7 +41,7 @@ int batadv_compare_orig(const struct hlist_node *node, const void *data2)
 	const void *data1 = container_of(node, struct batadv_orig_node,
 					 hash_entry);
 
-	return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
+	return ether_addr_equal_unaligned(data1, data2) ? 1 : 0;
 }
 
 /**
net/batman-adv/translation-table.c +1 -1
index 4add57d..5e66d4b 100644
@@ -51,7 +51,7 @@ static int batadv_compare_tt(const struct hlist_node *node, const void *data2)
 	const void *data1 = container_of(node, struct batadv_tt_common_entry,
 					 hash_entry);
 
-	return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
+	return ether_addr_equal_unaligned(data1, data2) ? 1 : 0;
 }
 
 /**
Signature · 1 line
1.8.0
#1 lore raw

On 23/12/13 06:10, Ding Tianhong wrote:

[...]

net/batman-adv/originator.c int batadv_compare_orig(const struct hlist_node *node, const void *data2) · line 44

Quoted 8 lines
net/batman-adv/originator.c +1 -1
@@ -41,7 +41,7 @@ int batadv_compare_orig(const struct hlist_node *node, const void *data2)
 	const void *data1 = container_of(node, struct batadv_orig_node,
 					 hash_entry);
 
-	return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
+	return ether_addr_equal_unaligned(data1, data2) ? 1 : 0;

ether_addr_equal_unaligned() returns a bool value which is implicitly converted to 1 or 0: there is no need for the ternary if anymore.

net/batman-adv/translation-table.c static int batadv_compare_tt(const struct hlist_node *node, const void *data2) · line 54

Quoted 13 lines
net/batman-adv/originator.c +0 -0
 }
 
 /**
net/batman-adv/translation-table.c +1 -1
index 4add57d..5e66d4b 100644
@@ -51,7 +51,7 @@ static int batadv_compare_tt(const struct hlist_node *node, const void *data2)
 	const void *data1 = container_of(node, struct batadv_tt_common_entry,
 					 hash_entry);
 
-	return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
+	return ether_addr_equal_unaligned(data1, data2) ? 1 : 0;

same here

Moreover, include linux/etherdevice.h in both files as explained in point 1) of Documentation/SubmitChecklist

Thanks.

Cheers,

Signature · 1 line
Antonio Quartulli
#2 lore raw
Quoted 10 lines · Antonio Quartulli

On 23/12/13 06:10, Ding Tianhong wrote:

[...]

Quoted 6 lines
net/batman-adv/originator.c +0 -0
@@ -41,7 +41,7 @@ int batadv_compare_orig(const struct hlist_node *node, const void *data2)
 	const void *data1 = container_of(node, struct batadv_orig_node,
 					 hash_entry);
 
Quoted 5 lines

net/batman-adv/originator.c int batadv_compare_orig(const struct hlist_node *node, const void *data2) · line 44

Quoted 2 lines
net/batman-adv/originator.c +1 -1
-	return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
+	return ether_addr_equal_unaligned(data1, data2) ? 1 : 0;

ether_addr_equal_unaligned() returns a bool value which is implicitly converted to 1 or 0: there is no need for the ternary if anymore.

Should these use batadv_compare_eth?

#3 lore raw
Quoted 11 lines · Joe Perches
Quoted 10 lines · Antonio Quartulli

On 23/12/13 06:10, Ding Tianhong wrote:

[...]

Quoted 6 lines
net/batman-adv/originator.c +0 -0
@@ -41,7 +41,7 @@ int batadv_compare_orig(const struct hlist_node *node, const void *data2)
 	const void *data1 = container_of(node, struct batadv_orig_node,
 					 hash_entry);
 
Quoted 8 lines
Quoted 5 lines

net/batman-adv/originator.c int batadv_compare_orig(const struct hlist_node *node, const void *data2) · line 44

Quoted 2 lines
net/batman-adv/originator.c +1 -1
-	return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
+	return ether_addr_equal_unaligned(data1, data2) ? 1 : 0;

ether_addr_equal_unaligned() returns a bool value which is implicitly converted to 1 or 0: there is no need for the ternary if anymore.

Should these use batadv_compare_eth?

That makes sense.

I was wondering whether we should get rid of batadv_compare_eth() at all and always use ether_addr_equal_unaligned(). The "unaligned explanation" is part of the name, so there is no need to use a commented helper anymore.

However, until that moment it is better to get stuck to batadv_compare_eth().

Ding, can you also follow Joe's suggestion for this patch please?

Thanks,

Signature · 1 line
Antonio Quartulli
#4 lore raw
Quoted 27 lines · Antonio Quartulli
Quoted 11 lines · Joe Perches
Quoted 10 lines · Antonio Quartulli

On 23/12/13 06:10, Ding Tianhong wrote:

[...]

Quoted 6 lines
net/batman-adv/originator.c +0 -0
@@ -41,7 +41,7 @@ int batadv_compare_orig(const struct hlist_node *node, const void *data2)
 	const void *data1 = container_of(node, struct batadv_orig_node,
 					 hash_entry);
 
Quoted 8 lines
Quoted 5 lines

net/batman-adv/originator.c int batadv_compare_orig(const struct hlist_node *node, const void *data2) · line 44

Quoted 2 lines
net/batman-adv/originator.c +1 -1
-	return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
+	return ether_addr_equal_unaligned(data1, data2) ? 1 : 0;

ether_addr_equal_unaligned() returns a bool value which is implicitly converted to 1 or 0: there is no need for the ternary if anymore.

Should these use batadv_compare_eth?

That makes sense.

I was wondering whether we should get rid of batadv_compare_eth() at all and always use ether_addr_equal_unaligned(). The "unaligned explanation" is part of the name, so there is no need to use a commented helper anymore.

Quoted 10 lines

However, until that moment it is better to get stuck to batadv_compare_eth().

Ding, can you also follow Joe's suggestion for this patch please?

Thanks,

Ok

#5 lore raw
In reply to Joe Perches
Quoted 11 lines · Joe Perches
Quoted 10 lines · Antonio Quartulli

On 23/12/13 06:10, Ding Tianhong wrote:

[...]

Quoted 6 lines
net/batman-adv/originator.c +0 -0
@@ -41,7 +41,7 @@ int batadv_compare_orig(const struct hlist_node *node, const void *data2)
 	const void *data1 = container_of(node, struct batadv_orig_node,
 					 hash_entry);
 
Quoted 9 lines
Quoted 5 lines

net/batman-adv/originator.c int batadv_compare_orig(const struct hlist_node *node, const void *data2) · line 44

Quoted 2 lines
net/batman-adv/originator.c +1 -1
-	return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
+	return ether_addr_equal_unaligned(data1, data2) ? 1 : 0;

ether_addr_equal_unaligned() returns a bool value which is implicitly converted to 1 or 0: there is no need for the ternary if anymore.

Should these use batadv_compare_eth?

Yes, and need to remove the checks for return value.

Regards
Ding

Quoted 2 lines
#6 lore raw
In reply to Antonio Quartulli
Quoted 34 lines · Antonio Quartulli

On 23/12/13 06:10, Ding Tianhong wrote:

[...]

net/batman-adv/originator.c int batadv_compare_orig(const struct hlist_node *node, const void *data2) · line 44

Quoted 8 lines
net/batman-adv/originator.c +1 -1
@@ -41,7 +41,7 @@ int batadv_compare_orig(const struct hlist_node *node, const void *data2)
 	const void *data1 = container_of(node, struct batadv_orig_node,
 					 hash_entry);
 
-	return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
+	return ether_addr_equal_unaligned(data1, data2) ? 1 : 0;

ether_addr_equal_unaligned() returns a bool value which is implicitly converted to 1 or 0: there is no need for the ternary if anymore.

net/batman-adv/translation-table.c static int batadv_compare_tt(const struct hlist_node *node, const void *data2) · line 54

Quoted 13 lines
net/batman-adv/originator.c +0 -0
 }
 
 /**
net/batman-adv/translation-table.c +1 -1
index 4add57d..5e66d4b 100644
@@ -51,7 +51,7 @@ static int batadv_compare_tt(const struct hlist_node *node, const void *data2)
 	const void *data1 = container_of(node, struct batadv_tt_common_entry,
 					 hash_entry);
 
-	return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
+	return ether_addr_equal_unaligned(data1, data2) ? 1 : 0;

same here

Quoted 9 lines

Moreover, include linux/etherdevice.h in both files as explained in point 1) of Documentation/SubmitChecklist

Thanks.

Cheers,

Yes, thanks a lot, fix it soon.

Regards
Ding