Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752700AbbBWTTH (ORCPT ); Mon, 23 Feb 2015 14:19:07 -0500 Received: from mail-wg0-f51.google.com ([74.125.82.51]:35873 "EHLO mail-wg0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752082AbbBWTTF (ORCPT ); Mon, 23 Feb 2015 14:19:05 -0500 Date: Mon, 23 Feb 2015 21:18:58 +0200 From: Aya Mahfouz To: Andy Whitcroft , Joe Perches , linux-kernel@vger.kernel.org Subject: [PATCH] scripts: checkpatch.pl: add 2 new checks on memset calls Message-ID: <20150223191858.GA21518@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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: 2113 Lines: 57 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. Cc: Julia Lawall Signed-off-by: Aya Mahfouz --- scripts/checkpatch.pl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index d124359..9619882 100755 --- 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", + "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($2)/; + } + elsif ($num =~ "0xff" && 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($2)/; + } + } + + # typecasts on min/max could be min_t/max_t if ($^V && $^V ge 5.10.0 && defined $stat && -- 1.9.3 -- 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/