Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754089Ab0HRUk1 (ORCPT ); Wed, 18 Aug 2010 16:40:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:3218 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751069Ab0HRUkX (ORCPT ); Wed, 18 Aug 2010 16:40:23 -0400 Date: Wed, 18 Aug 2010 16:40:17 -0400 From: Dave Jones To: apw@canonical.com Cc: Linux Kernel Subject: add memset checks to checkpatch.pl Message-ID: <20100818204016.GA29640@redhat.com> Mail-Followup-To: Dave Jones , apw@canonical.com, Linux Kernel MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-12-10) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1340 Lines: 34 Occasionally someone goofs the argument order to memset. This patch makes checkpatch catch those. I made memset with size of 0 an error, because it's never correct, whereas memset with a size of 1 isn't technically an incorrect thing to do so I left it as a warning. It may still be better to replace it with a single variable assignment in the false positive cases. Signed-off-by: Dave Jones diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 2039acd..3690173 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2794,6 +2794,14 @@ sub process { } } +# check for memset with reversed 2nd/3rd arguments. + if ($line =~ /memset.*\,(\ |)(0x|)0(\ |0|)\);/) { + ERROR("memset takes size as third argument, not the second.\n" . $herecurr); + } + if ($line =~ /memset.*\,(\ |)(0x|)1\);/) { + WARN("single byte memset is suspicious. Swapped 2nd/3rd argument?\n" . $herecurr); + } + # check for lockdep_set_novalidate_class if ($line =~ /^.\s*lockdep_set_novalidate_class\s*\(/ || $line =~ /__lockdep_no_validate__\s*\)/ ) { -- 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/