[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210805104353.GD26417@kili>
Date: Thu, 5 Aug 2021 13:43:53 +0300
From: Dan Carpenter <dan.carpenter@...cle.com>
To: Andy Whitcroft <apw@...onical.com>
Cc: Joe Perches <joe@...ches.com>,
Dwaipayan Ray <dwaipayanray1@...il.com>,
Lukas Bulwahn <lukas.bulwahn@...il.com>,
linux-kernel@...r.kernel.org, kernel-janitors@...r.kernel.org
Subject: [PATCH] checkpatch: prefer = {} initializations to = {0}
The "= {};" style empty struct initializer is preferred over = {0}.
It avoids the situation where the first struct member is a pointer and
that generates a Sparse warning about assigning using zero instead of
NULL. Also it's just nicer to look at.
Some people complain that {} is less portable but the kernel has
different portability requirements from userspace so this is not a
issue that we care about.
Signed-off-by: Dan Carpenter <dan.carpenter@...cle.com>
---
scripts/checkpatch.pl | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 461d4221e4a4..32c8a0ca6fd0 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4029,6 +4029,12 @@ sub process {
"Using $1 is unnecessary\n" . $herecurr);
}
+# prefer = {}; to = {0};
+ if ($line =~ /= \{ *0 *\}/) {
+ WARN("ZERO_INITIALIZER",
+ "= {} is preferred over = {0}\n" . $herecurr);
+ }
+
# Check for potential 'bare' types
my ($stat, $cond, $line_nr_next, $remain_next, $off_next,
$realline_next);
--
2.30.2
Powered by blists - more mailing lists