linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] checkpatch: prefer = {} initializations to = {0}
@ 2021-08-05 10:43 Dan Carpenter
  2021-08-05 12:27 ` Joe Perches
       [not found] ` <20210814135922.gIT6AWiUertQCb4-mO0DlLP6vG6pje2EMBqDKlqmBVM@z>
  0 siblings, 2 replies; 18+ messages in thread
From: Dan Carpenter @ 2021-08-05 10:43 UTC (permalink / raw)
  To: Andy Whitcroft
  Cc: Joe Perches, Dwaipayan Ray, Lukas Bulwahn, linux-kernel, kernel-janitors

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@oracle.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


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

end of thread, other threads:[~2021-08-16 19:05 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-05 10:43 [PATCH] checkpatch: prefer = {} initializations to = {0} Dan Carpenter
2021-08-05 12:27 ` Joe Perches
2021-08-05 18:04   ` Joe Perches
2021-08-05 18:17     ` Julia Lawall
2021-08-05 18:28       ` Joe Perches
2021-08-05 18:44         ` Julia Lawall
     [not found] ` <20210814135922.gIT6AWiUertQCb4-mO0DlLP6vG6pje2EMBqDKlqmBVM@z>
2021-08-14 13:59   ` Christophe JAILLET
2021-08-14 14:05     ` Marion & Christophe JAILLET
2021-08-14 14:38     ` Leon Romanovsky
2021-08-14 14:57       ` Al Viro
2021-08-14 15:52         ` Leon Romanovsky
2021-08-14 16:45           ` Al Viro
2021-08-14 14:44     ` Russell King (Oracle)
2021-08-14 14:52     ` Al Viro
2021-08-14 20:20       ` Christophe JAILLET
2021-08-16  6:55       ` Dan Carpenter
2021-08-16  7:23         ` Russell King (Oracle)
2021-08-16 19:05           ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).