From: akpm@linux-foundation.org
To: mm-commits@vger.kernel.org
Cc: joe@perches.com, akpm@linux-foundation.org, apw@canonical.com
Subject: + checkpatch-suggest-using-min_t-or-max_t.patch added to -mm tree
Date: Fri, 20 May 2011 15:24:57 -0700 [thread overview]
Message-ID: <201105202224.p4KMOvDa001783@imap1.linux-foundation.org> (raw)
The patch titled
checkpatch: suggest using min_t() or max_t()
has been added to the -mm tree. Its filename is
checkpatch-suggest-using-min_t-or-max_t.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/SubmitChecklist when testing your code ***
See http://userweb.kernel.org/~akpm/stuff/added-to-mm.txt to find
out what to do about this
The current -mm tree may be found at http://userweb.kernel.org/~akpm/mmotm/
------------------------------------------------------
Subject: checkpatch: suggest using min_t() or max_t()
From: Joe Perches <joe@perches.com>
A common issue with min() or max() is using a cast on one or both of the
arguments when using min_t/max_t could be better.
Add cast detection to uses of min/max and suggest an appropriate use of
min_t or max_t instead.
Suggested-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Joe Perches <joe@perches.com>
Cc: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
scripts/checkpatch.pl | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff -puN scripts/checkpatch.pl~checkpatch-suggest-using-min_t-or-max_t scripts/checkpatch.pl
--- a/scripts/checkpatch.pl~checkpatch-suggest-using-min_t-or-max_t
+++ a/scripts/checkpatch.pl
@@ -268,6 +268,20 @@ sub build_types {
}
build_types();
+our $match_balanced_parentheses = qr/(\((?:[^\(\)]++|(?-1))*\))/;
+
+our $Typecast = qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s*};
+our $LvalOrFunc = qr{($Lval)\s*($match_balanced_parentheses{0,1})\s*};
+
+sub deparenthesize {
+ my ($string) = @_;
+ return "" if (!defined($string));
+ $string =~ s@^\s*\(\s*@@g;
+ $string =~ s@\s*\)\s*$@@g;
+ $string =~ s@\s+@ @g;
+ return $string;
+}
+
$chk_signoff = 0 if ($file);
my @dep_includes = ();
@@ -2285,6 +2299,27 @@ sub process {
}
}
+# typecasts on min/max could be min_t/max_t
+ if ($line =~ /^\+.*\b(min|max)\s*\($Typecast{0,1}($LvalOrFunc)\s*,\s*$Typecast{0,1}($LvalOrFunc)\s*\)/) {
+ if (defined $2 || defined $7) {
+ my $call = $1;
+ my $cast1 = deparenthesize($2);
+ my $arg1 = $3;
+ my $cast2 = deparenthesize($7);
+ my $arg2 = $8;
+ my $cast;
+
+ if ($cast1 ne "" && $cast2 ne "") {
+ $cast = "$cast1 or $cast2";
+ } elsif ($cast1 ne "") {
+ $cast = $cast1;
+ } else {
+ $cast = $cast2;
+ }
+ WARN("$call() should probably be ${call}_t($cast, $arg1, $arg2)\n" . $herecurr);
+ }
+ }
+
# Need a space before open parenthesis after if, while etc
if ($line=~/\b(if|while|for|switch)\(/) {
ERROR("space required before the open parenthesis '('\n" . $herecurr);
_
Patches currently in -mm which might be from joe@perches.com are
origin.patch
linux-next.patch
maintainers-orphan-dmfe-move-tobias-ringstrom-to-credits.patch
checkpatch-add-check-for-line-continuations-in-quoted-strings.patch
checkpatch-add-foo_level-and-module_bar-to-80-column-exceptions.patch
checkpatch-fix-defect-in-printkkern_level-80-column-exceptions.patch
checkpatch-suggest-using-min_t-or-max_t.patch
reply other threads:[~2011-05-20 22:25 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=201105202224.p4KMOvDa001783@imap1.linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=apw@canonical.com \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mm-commits@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.