From: Dave Jones <davej@redhat.com>
To: apw@canonical.com
Cc: Linux Kernel <linux-kernel@vger.kernel.org>
Subject: add memset checks to checkpatch.pl
Date: Wed, 18 Aug 2010 16:40:17 -0400 [thread overview]
Message-ID: <20100818204016.GA29640@redhat.com> (raw)
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*\)/ ) {
next reply other threads:[~2010-08-18 20:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-18 20:40 Dave Jones [this message]
2010-08-18 21:32 ` add memset checks to checkpatch.pl 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100818204016.GA29640@redhat.com \
--to=davej@redhat.com \
--cc=apw@canonical.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.