From: Antony Pavlov <antonynpavlov@gmail.com>
To: barebox@lists.infradead.org
Subject: [PATCH 2/4] checkpatch.pl: check for common memset parameter issues against statements
Date: Wed, 5 Dec 2018 16:11:42 +0300 [thread overview]
Message-ID: <20181205131144.31512-3-antonynpavlov@gmail.com> (raw)
In-Reply-To: <20181205131144.31512-1-antonynpavlov@gmail.com>
Based on these Linux kernel commits
> 09c00c73f053a905 checkpatch: warn about memset with swapped arguments
> 54e165cf32610ec9 checkpatch: check for common memset parameter issues against statments
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
scripts/checkpatch.pl | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 4b9b9d06f3..d8a8e5004f 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2961,6 +2961,28 @@ sub process {
"sizeof(& should be avoided\n" . $herecurr);
}
+# Check for misused memsets
+ if (defined $stat && $stat =~ /\bmemset\s*\((.*)\)/s) {
+ my $args = $1;
+
+ # Flatten any parentheses and braces
+ while ($args =~ s/\([^\(\)]*\)/10/s ||
+ $args =~ s/\{[^\{\}]*\}/10/s ||
+ $args =~ s/\[[^\[\]]*\]/10/s)
+ {
+ }
+ # Extract the simplified arguments.
+ my ($ms_addr, $ms_val, $ms_size) =
+ split(/\s*,\s*/, $args);
+ if ($ms_size =~ /^(0x|)0$/i) {
+ ERROR("MEMSET",
+ "memset size is 3rd argument, not the second.\n" . $herecurr);
+ } elsif ($ms_size =~ /^(0x|)1$/i) {
+ WARN("MEMSET",
+ "single byte memset is suspicious. Swapped 2nd/3rd argument?\n" . $herecurr);
+ }
+ }
+
# check for new externs in .c files.
if ($realfile =~ /\.c$/ && defined $stat &&
$stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)
--
2.20.0.rc2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2018-12-05 13:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-05 13:11 [PATCH 0/4] checkpatch.pl: port misc linux commits Antony Pavlov
2018-12-05 13:11 ` [PATCH 1/4] checkpatch.pl: add ability to ignore various messages Antony Pavlov
2018-12-05 13:11 ` Antony Pavlov [this message]
2018-12-05 13:11 ` [PATCH 3/4] checkpatch.pl: use SPDX tag Antony Pavlov
2018-12-05 13:11 ` [PATCH 4/4] checkpatch.pl: check for #if 0/#if 1 Antony Pavlov
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=20181205131144.31512-3-antonynpavlov@gmail.com \
--to=antonynpavlov@gmail.com \
--cc=barebox@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox