History

checkpatch: suggest using eth_zero_addr() and eth_broadcast_addr()

Suggest using eth_zero_addr() or eth_broadcast_addr() instead of memset().

Mateusz Kulikowski committed 11 years ago

Commit 8617cd01 parent 9e20a851 file · +23 −0Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/checkpatch.pl+23−0
@@ -5165,6 +5165,29 @@ sub process { · 5164 unmodified lines
51655165 "Prefer ether_addr_equal() or ether_addr_equal_unaligned() over memcmp()\n" . "$here\n$stat\n")
51665166 }
51675167
5168+# check for memset(foo, 0x0, ETH_ALEN) that could be eth_zero_addr
5169+# check for memset(foo, 0xFF, ETH_ALEN) that could be eth_broadcast_addr
5170+ if ($^V && $^V ge 5.10.0 &&
5171+ defined $stat &&
5172+ $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
5173+
5174+ my $ms_val = $7;
5175+
5176+ if ($ms_val =~ /^(?:0x|)0+$/i) {
5177+ if (WARN("PREFER_ETH_ZERO_ADDR",
5178+ "Prefer eth_zero_addr over memset()\n" . "$here\n$stat\n") &&
5179+ $fix) {
5180+ $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*,\s*ETH_ALEN\s*\)/eth_zero_addr($2)/;
5181+ }
5182+ } elsif ($ms_val =~ /^(?:0xff|255)$/i) {
5183+ if (WARN("PREFER_ETH_BROADCAST_ADDR",
5184+ "Prefer eth_broadcast_addr() over memset()\n" . "$here\n$stat\n") &&
5185+ $fix) {
5186+ $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*,\s*ETH_ALEN\s*\)/eth_broadcast_addr($2)/;
5187+ }
5188+ }
5189+ }
5190+
51685191 # typecasts on min/max could be min_t/max_t
51695192 if ($^V && $^V ge 5.10.0 &&
51705193 defined $stat &&