diff mbox

[1/2] checkpatch: suggest using ether_addr_equal*()

Message ID 1429470246-15988-2-git-send-email-mateusz.kulikowski@gmail.com
State Not Applicable, archived
Delegated to: David Miller
Headers show

Commit Message

Mateusz Kulikowski April 19, 2015, 7:04 p.m. UTC
Check if memcmp() is used to compare ethernet addresses and suggest using
ether_addr_equal() or ether_addr_equal_unaligned()

Signed-off-by: Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
---
 scripts/checkpatch.pl | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Joe Perches April 19, 2015, 8:23 p.m. UTC | #1
On Sun, 2015-04-19 at 21:04 +0200, Mateusz Kulikowski wrote:
> Check if memcmp() is used to compare ethernet addresses and suggest using
> ether_addr_equal() or ether_addr_equal_unaligned()

Hi again Mateusz.

This is OK with me.

If you ever submit that ether_addr_copy_unaligned patch,
please update the checkpatch test for ether_addr_copy too.

Joe

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 89b1df4..3a1a01e 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -5035,6 +5035,13 @@  sub process {
 			}
 		}
 
+# Check for memcmp(foo, bar, ETH_ALEN) that could be ether_addr_equal*(foo, bar)
+		if ($^V && $^V ge 5.10.0 &&
+			$line =~ /^\+(?:.*?)\bmemcmp\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/s) {
+			WARN("PREFER_ETHER_ADDR_EQUAL",
+				 "Prefer ether_addr_equal() or ether_addr_equal_unaligned() over memcmp()\n" . $herecurr)
+		}
+
 # typecasts on min/max could be min_t/max_t
 		if ($^V && $^V ge 5.10.0 &&
 		    defined $stat &&