From: Joe Perches <joe@perches.com>
To: Aya Mahfouz <mahfouz.saif.elyazal@gmail.com>
Cc: Andy Whitcroft <apw@canonical.com>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] scripts: checkpatch.pl: add 2 new checks on memset calls
Date: Mon, 23 Feb 2015 19:06:27 -0800 [thread overview]
Message-ID: <1424747187.5342.3.camel@perches.com> (raw)
In-Reply-To: <20150223191858.GA21518@localhost.localdomain>
On Mon, 2015-02-23 at 21:18 +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.
>
> replace memset by eth_broadcast_addr if the second argument is
> the broadcast address (0xff). eth_broadcast_addr is a wrapper
> function for memset that sets the passed array the broadcast
> address. The size of the address has to be ETH_ALEN.
Hello Aya.
Good idea but:
there already is a test for memset at (-next) line 4893.
Please extend that as below instead of adding another test.
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -4918,6 +4918,25 @@ sub process {
> }
> }
>
> +# Check for memset(foo, 0x00|0xff, ETH_ALEN) that could be eth_zero_addr(foo)|eth_broadcast_addr(foo)
> + if ($^V && $^V ge 5.10.0 &&
> + $line =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/s) {
> + my $num = $7;
> + if ($num =~ "0x00" && WARN("PREFER_ETH_ZERO_ADDR",
# Check for misused memsets
if ($^V && $^V ge 5.10.0 &&
defined $stat &&
$stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*$FuncArg\s*\)/s) {
my $ms_addr = $2;
my $ms_val = $7;
my $ms_size = $12;
if ($ms_val =~ /^(?:0|0x0+)$/i &&
$ms_size =~ /^ETH_ALEN$/ &&
WARN("PREFER_ETH_ADDR_FUNC",
"..." . herecurr) &&
$fix) {
$fixed[$fixlinenr] =~ s/\bmemcpy\s*\(\s*\Q$ms_addr\E\s*,\s*\Q$ms_val\E\s*\,\s*ETH_ALEN\s*\)/eth_zero_addr($ms_addr)/;
} elsif ($ms_val =~ /^(?:0xff|255)$/i &&
$ms_size =~ /^ETH_ALEN$/ &&
WARN("PREFER_ETH_ADDR_FUNC",
"..." . herecurr) &&
$fix) {
$fixed[$fixlinenr] =~ s/\bmemcpy\s*\(\s*\Q$ms_addr\E\s*,\s*\Q$ms_val\E\s*\,\s*ETH_ALEN\s*\)/eth_broadcast_addr($ms_addr)/;
} elsif (...)
next prev parent reply other threads:[~2015-02-24 3:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-23 19:18 [PATCH] scripts: checkpatch.pl: add 2 new checks on memset calls Aya Mahfouz
2015-02-24 3:06 ` Joe Perches [this message]
2015-02-25 2:53 ` Aya Mahfouz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1424747187.5342.3.camel@perches.com \
--to=joe@perches.com \
--cc=apw@canonical.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mahfouz.saif.elyazal@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox