public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] checkpatch: check for trivial sizeofs
@ 2020-05-30 21:21 Denis Efremov
  2020-05-30 23:10 ` Joe Perches
  0 siblings, 1 reply; 2+ messages in thread
From: Denis Efremov @ 2020-05-30 21:21 UTC (permalink / raw)
  To: Joe Perches, Andy Whitcroft; +Cc: Denis Efremov, linux-kernel

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-05-30 23:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-30 21:21 [RFC PATCH] checkpatch: check for trivial sizeofs Denis Efremov
2020-05-30 23:10 ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox