Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752506AbbBXDGc (ORCPT ); Mon, 23 Feb 2015 22:06:32 -0500 Received: from smtprelay0238.hostedemail.com ([216.40.44.238]:35881 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751875AbbBXDGb (ORCPT ); Mon, 23 Feb 2015 22:06:31 -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:1542:1593:1594:1711:1730:1747:1777:1792:2197:2199:2393:2559:2562:2828:3138:3139:3140:3141:3142:3353:3622:3653:3865:3866:3867:3870:3871:3874:4321:4605:5007:6261:7903:8603:8957:10004:10400:10848:11026:11232:11473:11658:11914:12043:12049:12295:12296:12438:12517:12519:12679:12740:13071:13161:13229: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: nerve97_1b9f0e892412f X-Filterd-Recvd-Size: 2879 Message-ID: <1424747187.5342.3.camel@perches.com> Subject: Re: [PATCH] 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: Mon, 23 Feb 2015 19:06:27 -0800 In-Reply-To: <20150223191858.GA21518@localhost.localdomain> References: <20150223191858.GA21518@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: 2252 Lines: 63 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 (...) -- 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/