Skip to content

Commit 98a9bba

Browse files
JoePerchestorvalds
authored andcommitted
checkpatch: prefer ether_addr_copy to memcpy(foo, bar, ETH_ALEN)
ether_addr_copy was added for kernel version 3.14. It's slightly smaller/faster for some arches. Encourage its use. Signed-off-by: Joe Perches <joe@perches.com> Cc: Andy Whitcroft <apw@canonical.com> Cc: David Miller <davem@davemloft.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent bff5da4 commit 98a9bba

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎scripts/checkpatch.pl‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4087,6 +4087,16 @@ sub process {
40874087
}
40884088
}
40894089

4090+
# Check for memcpy(foo, bar, ETH_ALEN) that could be ether_addr_copy(foo, bar)
4091+
if ($^V && $^V ge 5.10.0 &&
4092+
$line =~ /^\+(?:.*?)\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/s) {
4093+
if (WARN("PREFER_ETHER_ADDR_COPY",
4094+
"Prefer ether_addr_copy() over memcpy() if the Ethernet addresses are __aligned(2)\n" . $herecurr) &&
4095+
$fix) {
4096+
$fixed[$linenr - 1] =~ s/\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/ether_addr_copy($2, $7)/;
4097+
}
4098+
}
4099+
40904100
# typecasts on min/max could be min_t/max_t
40914101
if ($^V && $^V ge 5.10.0 &&
40924102
defined $stat &&

0 commit comments

Comments
 (0)