Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752991AbbBYCxo (ORCPT ); Tue, 24 Feb 2015 21:53:44 -0500 Received: from mail-wi0-f171.google.com ([209.85.212.171]:47082 "EHLO mail-wi0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752892AbbBYCxn (ORCPT ); Tue, 24 Feb 2015 21:53:43 -0500 Date: Wed, 25 Feb 2015 04:53:37 +0200 From: Aya Mahfouz To: Joe Perches Cc: Andy Whitcroft , linux-kernel@vger.kernel.org Subject: Re: [PATCH] scripts: checkpatch.pl: add 2 new checks on memset calls Message-ID: <20150225025337.GA9220@localhost.localdomain> References: <20150223191858.GA21518@localhost.localdomain> <1424747187.5342.3.camel@perches.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1424747187.5342.3.camel@perches.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2594 Lines: 73 On Mon, Feb 23, 2015 at 07:06:27PM -0800, Joe Perches wrote: > 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. > Hello Joe, I've adjusted the checks as you requested. Kindly let me know if there is something else that should be done. Kind Regards, Aya Saif El-yazal Mahfouz > > 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/