* [PATCH v3] scripts: checkpatch.pl: add 2 new checks on memset
@ 2015-03-01 21:43 Aya Mahfouz
2015-03-01 22:13 ` Joe Perches
0 siblings, 1 reply; 4+ messages in thread
From: Aya Mahfouz @ 2015-03-01 21:43 UTC (permalink / raw)
To: Andy Whitcroft, Joe Perches, linux-kernel
calls
Reply-To:
Add 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.
In addition, the regex assigned to the variable $stat has been
restricted to handle memset function calls of the form:
[<identifer> =]* memset(<arg1>, <arg2>, <arg3>)
Cc: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Aya Mahfouz <mahfouz.saif.elyazal@gmail.com>
Signed-off-by: Joe Perches <joe@perches.com>
---
v2: adjusted all checks on memset calls to be in one body
v3: adjusted all regular expressions per Joe Perches suggestions. Added
a Signed-off-by tag for Joe since all the important regular expressions
are written by him.
scripts/checkpatch.pl | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index d124359..cbe973e 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4890,10 +4890,11 @@ sub process {
}
}
-# Check for misused memsets
+# Check for misused memsets then check for memset(foo, 0x00|0xff, ETH_ALEN)
+# calls that could be eth_zero_addr(foo)|eth_broadcast_addr(foo)
if ($^V && $^V ge 5.10.0 &&
defined $stat &&
- $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*$FuncArg\s*\)/s) {
+ $stat =~ /^\+(?:\s*$Ident\s*=)?\s*memset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*$FuncArg\s*\)/s) {
my $ms_addr = $2;
my $ms_val = $7;
@@ -4905,6 +4906,18 @@ sub process {
} elsif ($ms_size =~ /^(0x|)1$/i) {
WARN("MEMSET",
"single byte memset is suspicious. Swapped 2nd/3rd argument?\n" . "$here\n$stat\n");
+ } elsif ($ms_val =~ /^(?:0x)?0+$/i &&
+ $ms_size =~ /^ETH_ALEN$/ &&
+ WARN("PREFER_ETH_ADDR",
+ "Prefer eth_zero_addr() over memset() if the second address is 0\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\bmemset\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",
+ "Prefer eth_broadcast_addr() over memset() if the second address is 0xff\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*\Q$ms_addr\E\s*,\s*\Q$ms_val\E\s*,\s*ETH_ALEN\s*\)/eth_broadcast_addr($ms_addr)/;
}
}
--
1.9.3
--
Kind Regards,
Aya Saif El-yazal Mahfouz
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3] scripts: checkpatch.pl: add 2 new checks on memset
2015-03-01 21:43 [PATCH v3] scripts: checkpatch.pl: add 2 new checks on memset Aya Mahfouz
@ 2015-03-01 22:13 ` Joe Perches
2015-03-01 23:38 ` Aya Mahfouz
0 siblings, 1 reply; 4+ messages in thread
From: Joe Perches @ 2015-03-01 22:13 UTC (permalink / raw)
To: Aya Mahfouz; +Cc: Andy Whitcroft, linux-kernel
On Sun, 2015-03-01 at 23:43 +0200, Aya Mahfouz wrote:
> calls
> Reply-To:
>
> Add 2 new checks on memset calls in the file checkpatch.pl as follows:
Hi again Aya
The initial 3 lines here aren't necessary.
I think it'd be a better subject line with something like
"checkpatch: prefer eth_<foo>_addr over memset(,,ETH_ALEN)"
Please cc Andrew Morton <akpm@linux-foundation.org>
And please also don't add Signed-off-by: lines for
anyone other than yourself.
Other than those things:
Acked-by: Joe Perches <joe@perches.com>
> 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.
>
> In addition, the regex assigned to the variable $stat has been
> restricted to handle memset function calls of the form:
> [<identifer> =]* memset(<arg1>, <arg2>, <arg3>)
>
> Cc: Julia Lawall <julia.lawall@lip6.fr>
> Signed-off-by: Aya Mahfouz <mahfouz.saif.elyazal@gmail.com>
> Signed-off-by: Joe Perches <joe@perches.com>
> ---
> v2: adjusted all checks on memset calls to be in one body
> v3: adjusted all regular expressions per Joe Perches suggestions. Added
> a Signed-off-by tag for Joe since all the important regular expressions
> are written by him.
>
> scripts/checkpatch.pl | 17 +++++++++++++++--
> 1 file changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index d124359..cbe973e 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -4890,10 +4890,11 @@ sub process {
> }
> }
>
> -# Check for misused memsets
> +# Check for misused memsets then check for memset(foo, 0x00|0xff, ETH_ALEN)
> +# calls that could be eth_zero_addr(foo)|eth_broadcast_addr(foo)
> if ($^V && $^V ge 5.10.0 &&
> defined $stat &&
> - $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*$FuncArg\s*\)/s) {
> + $stat =~ /^\+(?:\s*$Ident\s*=)?\s*memset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*$FuncArg\s*\)/s) {
>
> my $ms_addr = $2;
> my $ms_val = $7;
> @@ -4905,6 +4906,18 @@ sub process {
> } elsif ($ms_size =~ /^(0x|)1$/i) {
> WARN("MEMSET",
> "single byte memset is suspicious. Swapped 2nd/3rd argument?\n" . "$here\n$stat\n");
> + } elsif ($ms_val =~ /^(?:0x)?0+$/i &&
> + $ms_size =~ /^ETH_ALEN$/ &&
> + WARN("PREFER_ETH_ADDR",
> + "Prefer eth_zero_addr() over memset() if the second address is 0\n" . $herecurr) &&
> + $fix) {
> + $fixed[$fixlinenr] =~ s/\bmemset\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",
> + "Prefer eth_broadcast_addr() over memset() if the second address is 0xff\n" . $herecurr) &&
> + $fix) {
> + $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*\Q$ms_addr\E\s*,\s*\Q$ms_val\E\s*,\s*ETH_ALEN\s*\)/eth_broadcast_addr($ms_addr)/;
> }
> }
>
> --
> 1.9.3
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] scripts: checkpatch.pl: add 2 new checks on memset
2015-03-01 22:13 ` Joe Perches
@ 2015-03-01 23:38 ` Aya Mahfouz
2015-03-01 23:45 ` Joe Perches
0 siblings, 1 reply; 4+ messages in thread
From: Aya Mahfouz @ 2015-03-01 23:38 UTC (permalink / raw)
To: Joe Perches; +Cc: Andy Whitcroft, linux-kernel
On Sun, Mar 01, 2015 at 02:13:21PM -0800, Joe Perches wrote:
> On Sun, 2015-03-01 at 23:43 +0200, Aya Mahfouz wrote:
> > calls
> > Reply-To:
> >
> > Add 2 new checks on memset calls in the file checkpatch.pl as follows:
>
> Hi again Aya
>
> The initial 3 lines here aren't necessary.
>
> I think it'd be a better subject line with something like
> "checkpatch: prefer eth_<foo>_addr over memset(,,ETH_ALEN)"
>
ok, should I resend it as a fresh patch or send the patch with a new
subject line and state that it is v4?
> Please cc Andrew Morton <akpm@linux-foundation.org>
> And please also don't add Signed-off-by: lines for
> anyone other than yourself.
>
ok, I will cc Andrew. As for your tag, I couldn't take credit
for the regex that I did not write. Will not do it in the future again
unless the other side agrees to it.
> Other than those things:
> Acked-by: Joe Perches <joe@perches.com>
>
> > 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.
> >
> > In addition, the regex assigned to the variable $stat has been
> > restricted to handle memset function calls of the form:
> > [<identifer> =]* memset(<arg1>, <arg2>, <arg3>)
> >
> > Cc: Julia Lawall <julia.lawall@lip6.fr>
> > Signed-off-by: Aya Mahfouz <mahfouz.saif.elyazal@gmail.com>
> > Signed-off-by: Joe Perches <joe@perches.com>
> > ---
> > v2: adjusted all checks on memset calls to be in one body
> > v3: adjusted all regular expressions per Joe Perches suggestions. Added
> > a Signed-off-by tag for Joe since all the important regular expressions
> > are written by him.
> >
> > scripts/checkpatch.pl | 17 +++++++++++++++--
> > 1 file changed, 15 insertions(+), 2 deletions(-)
> >
> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > index d124359..cbe973e 100755
> > --- a/scripts/checkpatch.pl
> > +++ b/scripts/checkpatch.pl
> > @@ -4890,10 +4890,11 @@ sub process {
> > }
> > }
> >
> > -# Check for misused memsets
> > +# Check for misused memsets then check for memset(foo, 0x00|0xff, ETH_ALEN)
> > +# calls that could be eth_zero_addr(foo)|eth_broadcast_addr(foo)
> > if ($^V && $^V ge 5.10.0 &&
> > defined $stat &&
> > - $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*$FuncArg\s*\)/s) {
> > + $stat =~ /^\+(?:\s*$Ident\s*=)?\s*memset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*$FuncArg\s*\)/s) {
> >
> > my $ms_addr = $2;
> > my $ms_val = $7;
> > @@ -4905,6 +4906,18 @@ sub process {
> > } elsif ($ms_size =~ /^(0x|)1$/i) {
> > WARN("MEMSET",
> > "single byte memset is suspicious. Swapped 2nd/3rd argument?\n" . "$here\n$stat\n");
> > + } elsif ($ms_val =~ /^(?:0x)?0+$/i &&
> > + $ms_size =~ /^ETH_ALEN$/ &&
> > + WARN("PREFER_ETH_ADDR",
> > + "Prefer eth_zero_addr() over memset() if the second address is 0\n" . $herecurr) &&
> > + $fix) {
> > + $fixed[$fixlinenr] =~ s/\bmemset\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",
> > + "Prefer eth_broadcast_addr() over memset() if the second address is 0xff\n" . $herecurr) &&
> > + $fix) {
> > + $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*\Q$ms_addr\E\s*,\s*\Q$ms_val\E\s*,\s*ETH_ALEN\s*\)/eth_broadcast_addr($ms_addr)/;
> > }
> > }
> >
> > --
> > 1.9.3
> >
> >
>
>
>
--
Kind Regards,
Aya Saif El-yazal Mahfouz
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] scripts: checkpatch.pl: add 2 new checks on memset
2015-03-01 23:38 ` Aya Mahfouz
@ 2015-03-01 23:45 ` Joe Perches
0 siblings, 0 replies; 4+ messages in thread
From: Joe Perches @ 2015-03-01 23:45 UTC (permalink / raw)
To: Aya Mahfouz; +Cc: Andy Whitcroft, linux-kernel
On Mon, 2015-03-02 at 01:38 +0200, Aya Mahfouz wrote:
> On Sun, Mar 01, 2015 at 02:13:21PM -0800, Joe Perches wrote:
> > On Sun, 2015-03-01 at 23:43 +0200, Aya Mahfouz wrote:
> > > calls
> > > Reply-To:
> > >
> > > Add 2 new checks on memset calls in the file checkpatch.pl as follows:
> >
> > Hi again Aya
> >
> > The initial 3 lines here aren't necessary.
> >
> > I think it'd be a better subject line with something like
> > "checkpatch: prefer eth_<foo>_addr over memset(,,ETH_ALEN)"
> >
> ok, should I resend it as a fresh patch or send the patch with a new
> subject line and state that it is v4?
Send V4 with new subject and cc Andrew.
> > Please cc Andrew Morton <akpm@linux-foundation.org>
> > And please also don't add Signed-off-by: lines for
> > anyone other than yourself.
> >
> ok, I will cc Andrew. As for your tag, I couldn't take credit
> for the regex that I did not write. Will not do it in the future again
> unless the other side agrees to it.
No worries from me.
"Suggested-by:" or "Portions-by:" or just some text
with "credit to: <name>" for the suggestions, etc
cheers, Joe
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-03-01 23:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-01 21:43 [PATCH v3] scripts: checkpatch.pl: add 2 new checks on memset Aya Mahfouz
2015-03-01 22:13 ` Joe Perches
2015-03-01 23:38 ` Aya Mahfouz
2015-03-01 23:45 ` Joe Perches
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox