Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752316AbbBYFpr (ORCPT ); Wed, 25 Feb 2015 00:45:47 -0500 Received: from smtprelay0090.hostedemail.com ([216.40.44.90]:40986 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750747AbbBYFpq (ORCPT ); Wed, 25 Feb 2015 00:45:46 -0500 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::,RULES_HIT:41:355:379:541:599:982:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1543:1593:1594:1711:1730:1747:1777:1792:2197:2199:2393:2553:2559:2562:2828:3138:3139:3140:3141:3142:3354:3622:3653:3865:3867:3870:3871:3872:3873:3874:4321:4605:5007:6119:6261:7903:7974:8957:10004:10400:10848:11026:11232:11473:11658:11914:12043:12517:12519:12555:12740:14093:14097:21080,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0 X-HE-Tag: apple13_1515e443ff01a X-Filterd-Recvd-Size: 4351 Message-ID: <1424843143.11070.11.camel@perches.com> Subject: Re: [PATCH v2] scripts: checkpatch.pl: add 2 new checks on memset calls From: Joe Perches To: Aya Mahfouz Cc: Andy Whitcroft , linux-kernel@vger.kernel.org Date: Tue, 24 Feb 2015 21:45:43 -0800 In-Reply-To: <20150225045907.GC9220@localhost.localdomain> References: <20150225024043.GA9120@localhost.localdomain> <1424833852.11070.1.camel@perches.com> <20150225043521.GB9220@localhost.localdomain> <1424839283.11070.9.camel@perches.com> <20150225045907.GC9220@localhost.localdomain> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.12.7-0ubuntu1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3510 Lines: 90 On Wed, 2015-02-25 at 06:59 +0200, Aya Mahfouz wrote: > On Tue, Feb 24, 2015 at 08:41:23PM -0800, Joe Perches wrote: > > On Wed, 2015-02-25 at 06:35 +0200, Aya Mahfouz wrote: > > > On Tue, Feb 24, 2015 at 07:10:52PM -0800, Joe Perches wrote: > > > > 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: > > [] > > > ok, I didn't see your suggestion, sorry. > > > > No worries. > > > > > Can you look at the following > > > modification before sending the third patch? I don't use $stat because > > > I get false positives with it. > > > > Please describe the false positives. > > > > > > ok, here are the relevant warnings issued by checkpatch.pl when using > $stat for the file drivers/staging/rtl8188eu/os_dep/ioctl_linux.c. > The only correct results are lines 95, 830, 1031, 1040, 1908. > > WARNING: Prefer eth_zero_addr() over memset() if the second address is 0x00 > #95: FILE: drivers/staging/rtl8188eu/os_dep/ioctl_linux.c:95: > + memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN); > > > WARNING: Prefer eth_zero_addr() over memset() if the second address is 0x00 > #775: FILE: drivers/staging/rtl8188eu/os_dep/ioctl_linux.c:775: > +} [] Try this: --- scripts/checkpatch.pl | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index d124359..9127c65 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; @@ -4901,10 +4902,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_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)/; } } -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/