Suggest using eth_zero_addr() or eth_broadcast_addr() instead of memset().
Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all
Unified · Split
| @@ -5165,6 +5165,29 @@ sub process { · 5164 unmodified lines | ||
| 5165 | 5165 | "Prefer ether_addr_equal() or ether_addr_equal_unaligned() over memcmp()\n" . "$here\n$stat\n") |
| 5166 | 5166 | } |
| 5167 | 5167 | |
| 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 | + | |
| 5168 | 5191 | # typecasts on min/max could be min_t/max_t |
| 5169 | 5192 | if ($^V && $^V ge 5.10.0 && |
| 5170 | 5193 | defined $stat && |