All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Hurley <peter@hurleysoftware.com>, linux-kernel@vger.kernel.org
Subject: [PATCH] checkpatch: Add --strict test for function pointer calling style
Date: Wed, 05 Nov 2014 10:41:57 -0800	[thread overview]
Message-ID: <1415212917.6634.17.camel@perches.com> (raw)
In-Reply-To: <1415208392-16189-3-git-send-email-peter@hurleysoftware.com>

Peter Hurley wrote:

The use of older function ptr calling style, (*fn)(), makes static
analysis more error-prone; replace with modern fn() style.

So make checkpatch emit a --strict test for that condition.

Update the unnecessary parentheses test for dereferencing
objects at the same time and create a $fix mechanism too.

Signed-off-by: Joe Perches <joe@perches.com>
---
 scripts/checkpatch.pl | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 24d6702..552e5dd 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3838,9 +3838,27 @@ sub process {
 # ie: &(foo->bar) should be &foo->bar and *(foo->bar) should be *foo->bar
 
 		while ($line =~ /(?:[^&]&\s*|\*)\(\s*($Ident\s*(?:$Member\s*)+)\s*\)/g) {
-			CHK("UNNECESSARY_PARENTHESES",
-			    "Unnecessary parentheses around $1\n" . $herecurr);
-		    }
+			my $var = $1;
+			if (CHK("UNNECESSARY_PARENTHESES",
+				"Unnecessary parentheses around $var\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/\(\s*\Q$var\E\s*\)/$var/;
+			}
+		}
+
+# check for unnecessary parentheses around function pointer uses
+# ie: (foo->bar)(); should be foo->bar();
+# but not "if (foo->bar) (" to avoid some false positives
+		if ($line =~ /(\bif\s*|)(\(\s*$Ident\s*(?:$Member\s*)+\))[ \t]*\(/ && $1 !~ /^if/) {
+			my $var = $2;
+			if (CHK("UNNECESSARY_PARENTHESES",
+				"Unnecessary parentheses around function pointer $var\n" . $herecurr) &&
+			    $fix) {
+				my $var2 = deparenthesize($var);
+				$var2 =~ s/\s//g;
+				$fixed[$fixlinenr] =~ s/\Q$var\E/$var2/;
+			}
+		}
 
 #goto labels aren't indented, allow a single space however
 		if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and



  reply	other threads:[~2014-11-05 18:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-05 17:26 [PATCH -next 0/9] various tty cleanups Peter Hurley
2014-11-05 17:26 ` [PATCH -next 1/9] tty: Replace open-coded test with tty_hung_up_p() Peter Hurley
2014-11-05 17:26 ` [PATCH -next 2/9] tty: Call methods in modern style Peter Hurley
2014-11-05 18:41   ` Joe Perches [this message]
2014-11-05 19:12     ` [PATCH] checkpatch: Add --strict test for function pointer calling style Peter Hurley
2014-11-05 19:30       ` Joe Perches
2014-11-05 17:26 ` [PATCH -next 3/9] tty: Remove defunct pcxe_open() declaration Peter Hurley
2014-11-05 17:26 ` [PATCH -next 4/9] tty: Remove defunct serial_console_init() declaration Peter Hurley
2014-11-05 17:26 ` [PATCH -next 5/9] serial: hp300: Remove obsolete comments Peter Hurley
2014-11-05 18:36   ` Geert Uytterhoeven
2014-11-05 17:26 ` [PATCH -next 6/9] cris: Remove obsolete ASYNC_SPLIT_TERMIOS behavior Peter Hurley
2014-11-06  8:23   ` Jesper Nilsson
2014-11-05 17:26 ` [PATCH -next 7/9] tty: Document defunct ASYNC_SPLIT_TERMIOS flag in uapi header Peter Hurley
2014-11-05 17:26 ` [PATCH -next 8/9] vt: Remove vt_get_kmsg_redirect() from " Peter Hurley
2014-11-05 17:26 ` [PATCH -next 9/9] serial: 8250_em: Remove out-of-memory message Peter Hurley

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=1415212917.6634.17.camel@perches.com \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peter@hurleysoftware.com \
    /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.