mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: dgilbert@interlog.com, LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] checkpatch: Improve TYPECAST_INT_CONSTANT test message
Date: Mon, 18 Jan 2021 09:19:18 -0800	[thread overview]
Message-ID: <ecefe8dcb93fe7028311b69dd297ba52224233d4.camel@perches.com> (raw)
In-Reply-To: <b9861410-f23d-62aa-cdc9-9e2918359a86@interlog.com>

Improve the TYPECAST_INT_CONSTANT test by showing the suggested
conversion for various type of uses like (unsigned int)1 to 1U.

Signed-off-by: Joe Perches <joe@perches.com>
---

Douglas Gilbert sent me a private email (and in that email said he
'loves to hate checkpatch' ;) complaining that checkpatch warned on the
use of the cast of '(unsigned int)1' so make it more obvious why the
message is emitted by always showing the suggested conversion.

 scripts/checkpatch.pl | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 016115a62a9f..4f8494527139 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6527,18 +6527,18 @@ sub process {
 		if ($line =~ /(\(\s*$C90_int_types\s*\)\s*)($Constant)\b/) {
 			my $cast = $1;
 			my $const = $2;
+			my $suffix = "";
+			my $newconst = $const;
+			$newconst =~ s/${Int_type}$//;
+			$suffix .= 'U' if ($cast =~ /\bunsigned\b/);
+			if ($cast =~ /\blong\s+long\b/) {
+			    $suffix .= 'LL';
+			} elsif ($cast =~ /\blong\b/) {
+			    $suffix .= 'L';
+			}
 			if (WARN("TYPECAST_INT_CONSTANT",
-				 "Unnecessary typecast of c90 int constant\n" . $herecurr) &&
+				 "Unnecessary typecast of c90 int constant - '$cast$const' could be '$const$suffix'\n" . $herecurr) &&
 			    $fix) {
-				my $suffix = "";
-				my $newconst = $const;
-				$newconst =~ s/${Int_type}$//;
-				$suffix .= 'U' if ($cast =~ /\bunsigned\b/);
-				if ($cast =~ /\blong\s+long\b/) {
-					$suffix .= 'LL';
-				} elsif ($cast =~ /\blong\b/) {
-					$suffix .= 'L';
-				}
 				$fixed[$fixlinenr] =~ s/\Q$cast\E$const\b/$newconst$suffix/;
 			}
 		}



       reply	other threads:[~2021-01-18 17:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <f11f2ee7-a909-6ab7-f5a8-67a46e11c1e5@interlog.com>
     [not found] ` <63178794d14d12f28ccf87707f420ba97b90f6fd.camel@perches.com>
     [not found]   ` <b9861410-f23d-62aa-cdc9-9e2918359a86@interlog.com>
2021-01-18 17:19     ` Joe Perches [this message]
2021-01-18 20:16       ` Douglas Gilbert

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=ecefe8dcb93fe7028311b69dd297ba52224233d4.camel@perches.com \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=dgilbert@interlog.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®