Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752592AbbBYDK5 (ORCPT ); Tue, 24 Feb 2015 22:10:57 -0500 Received: from smtprelay0064.hostedemail.com ([216.40.44.64]:46223 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751226AbbBYDKz (ORCPT ); Tue, 24 Feb 2015 22:10:55 -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:1541:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2828:3138:3139:3140:3141:3142:3353:3622:3653:3865:3866:3867:3868:3870:3871:3874:4321:4605:5007:6261:7903:7974:8603:8957:10004:10400:10848:11026:11232:11473:11658:11914:12043:12296:12438:12517:12519:12740:13019:13069:13311:13357: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: team94_7c42776509707 X-Filterd-Recvd-Size: 2638 Message-ID: <1424833852.11070.1.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 19:10:52 -0800 In-Reply-To: <20150225024043.GA9120@localhost.localdomain> References: <20150225024043.GA9120@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: 2020 Lines: 50 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@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/