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.kulikow...@gmail.com>
---
 scripts/checkpatch.pl | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 89b1df4..b9ea436 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 &&
-- 
1.8.4.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to