All of lore.kernel.org
 help / color / mirror / Atom feed
From: Denis Efremov <efremov@linux.com>
To: Joe Perches <joe@perches.com>, Andy Whitcroft <apw@canonical.com>
Cc: Denis Efremov <efremov@linux.com>, linux-kernel@vger.kernel.org
Subject: [RFC PATCH] checkpatch: check for trivial sizeofs
Date: Sun, 31 May 2020 00:21:29 +0300	[thread overview]
Message-ID: <20200530212129.7498-1-efremov@linux.com> (raw)

sizeof(char) and its variations in most cases doesn't make code more clear.
It only makes code wordy.

Signed-off-by: Denis Efremov <efremov@linux.com>
---
 scripts/checkpatch.pl | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index eac40f0abd56..9dd338b125d2 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6045,6 +6045,13 @@ sub process {
 			}
 		}
 
+# check for trivial sizeof(char) == 1
+		if ($line =~ /\bsizeof\s*\(\s*((?:(?:un)?signed\s+)?char|(?:__)?u8|u?int8_t|[us]?byte(?:_t)?)\s*\)/) {
+			my $byte = $1;
+			CHK("SIZEOF_TRIVIAL",
+			     "redundant sizeof($byte) == 1 \n" . $herecurr);
+		}
+
 # check for struct spinlock declarations
 		if ($line =~ /^.\s*\bstruct\s+spinlock\s+\w+\s*;/) {
 			WARN("USE_SPINLOCK_T",
-- 
2.26.2


             reply	other threads:[~2020-05-30 21:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-30 21:21 Denis Efremov [this message]
2020-05-30 23:10 ` [RFC PATCH] checkpatch: check for trivial sizeofs Joe Perches

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=20200530212129.7498-1-efremov@linux.com \
    --to=efremov@linux.com \
    --cc=apw@canonical.com \
    --cc=joe@perches.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.