Re: [PATCH v2] scripts: checkpatch.pl: add 2 new checks on memset calls

From: Joe Perches
Date: Tue Feb 24 2015 - 22:11:00 EST


On Wed, 2015-02-25 at 04:40 +0200, Aya Mahfouz wrote:
> This patch adds 2 new checks on memset calls in the file
> checkpatch.pl as follows:
>
> replace memset by eth_zero_addr if the second argument is
> an address of zeros (0x00). eth_zero_addr is a wrapper function
> for memset that takes an address array to set as zero. The size
> address has to be ETH_ALEN.

[]
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -4901,10 +4901,22 @@ sub process {
>
> if ($ms_size =~ /^(0x|)0$/i) {
> ERROR("MEMSET",
> - "memset to 0's uses 0 as the 2nd argument, not the 3rd\n" . "$here\n$stat\n");
> + "memset to 0's uses 0 as the 2nd argument, not the 3rd\n" . "$here\n$line\n");
> } elsif ($ms_size =~ /^(0x|)1$/i) {
> WARN("MEMSET",
> - "single byte memset is suspicious. Swapped 2nd/3rd argument?\n" . "$here\n$stat\n");
> + "single byte memset is suspicious. Swapped 2nd/3rd argument?\n" . "$here\n$line\n");
> + } elsif ($ms_size =~ /^ETH_ALEN/i) {
> + if ($ms_val =~ /^0x00/i && WARN("PREFER_ETH_ZERO_ADDR",

This isn't right. Look again at what I suggested.

This would match 0x00ff and wouldn't match 0

> + "Prefer eth_zero_addr() over memset() if the second address is 0x00\n" . $herecurr) &&
> + $fix) {
> +
> + $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/eth_zero_addr($ms_addr)/;
> + } elsif ($ms_val =~ /^0xff/i && WARN("PREFER_ETH_BROADCAST_ADDR",
> + "Prefer eth_broadcast_addr() over memset() if the second address is 0xff\n" . $herecurr) &&
> + $fix) {
> +
> + $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/eth_broadcast_addr($ms_addr)/;
> + }
> }
> }
>



--
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/