Re: [PATCH v2 2/2] checkpatch: suggest using eth_zero_addr() and eth_broadcast_addr()

From: Joe Perches
Date: Sun Apr 19 2015 - 21:13:25 EST


On Mon, 2015-04-20 at 00:16 +0200, Mateusz Kulikowski wrote:
> Suggest using eth_zero_addr() or eth_broadcast_addr() instead of memset().

Hi again Mateusz

> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -5042,6 +5042,22 @@ sub process {
> "Prefer ether_addr_equal() or ether_addr_equal_unaligned() over memcmp()\n" . $herecurr)
> }
>
> +# check for memset(foo, 0x0, ETH_ALEN) that could be eth_zero_addr
> +# check for memset(foo, 0xFF, ETH_ALEN) that could be eth_broadcast_addr
> + if ($^V && $^V ge 5.10.0 &&
> + $line =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/s) {

Because you are working with $line and not $stat,
the last /s isn't useful here.

$line is always a single line.

> + my $ms_val = $7;
> +
> + if ($ms_val =~ /^(0x|)0+$/i) {

It's trivially faster to use (?:0x|) so the 0x is not captured.

> + WARN("PREFER_ETH_ZERO_ADDR",
> + "Prefer eth_zero_addr over memset()\n" . $herecurr);

And these could be:
if (WARN(...) &&
$fix) {
$fixed[$fixlinenr] = s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*,\s*ETH_ALEN\s*\)/eth_zero_addr($1)/;
}
}

> + } elsif ($ms_val =~ /^(?:0xff|255)$/i) {
> + WARN("PREFER_ETH_BROADCAST_ADDR",
> + "Prefer eth_broadcast_addr() over memset()\n" . $herecurr);

if (WARN(...) &&
$fix) {
$fixed[$fixlinenr] = s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*,\s*ETH_ALEN\s*\)/eth_broadcast_addr($1)/;
}

cheers, Joe

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