public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* add memset checks to checkpatch.pl
@ 2010-08-18 20:40 Dave Jones
  2010-08-18 21:32 ` Joe Perches
  0 siblings, 1 reply; 8+ messages in thread
From: Dave Jones @ 2010-08-18 20:40 UTC (permalink / raw)
  To: apw; +Cc: Linux Kernel

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 <davej@redhat.com>

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*\)/ ) {

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-09-02 13:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-18 20:40 add memset checks to checkpatch.pl Dave Jones
2010-08-18 21:32 ` Joe Perches
2010-08-18 21:48   ` Dave Jones
2010-08-18 21:57     ` Joe Perches
2010-08-18 22:17       ` Dave Jones
2010-08-18 23:38         ` Joe Perches
2010-09-02 10:52           ` Andy Whitcroft
2010-09-02 13:17             ` Ævar Arnfjörð Bjarmason

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox