Received: by 2002:a05:6a10:c7d3:0:0:0:0 with SMTP id h19csp293670pxy; Sat, 14 Aug 2021 07:08:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJCDNxrT7Vfigfs2q5wKyvHSUXlL2Wc8Ja3PZSh9WPlU57ox+Jo5qUjTP9h4wDrSNl9u5c X-Received: by 2002:a05:6e02:12a3:: with SMTP id f3mr1993063ilr.46.1628950111303; Sat, 14 Aug 2021 07:08:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628950111; cv=none; d=google.com; s=arc-20160816; b=Wz4yetnv86uLzlAjTws/eM1uo0n87kEHydBicLODAHA+SljnxtJtm+zF2PDf326iY/ LzZuo1EtU9zcl/mGls2dyraV15uoaZOEyWMSvLaR0eG+Ugr8r8ovuIBIV3066VcVLJmE GmncjFglSkOdpQjaDRhplWnOsRB7XqxEZGPm750gBi3vRmx853O+858Pm7PpxS34LBVN U9YuCxZ79WHGOK6QNyz+BGr7rvlrb2losY1XWCu/BIwofZv631KMuJ4WxrqcusT9FXNg zeYKg8uEpBSZ44NJ5gn3gP5efNQdar/dwRlLGM4KaOvTqjj96iwLjAARXHQ7mJbjbAoo 7O3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:from:subject; bh=SaF6hAyOPz1XfkS/L3+jHrzzWWgDhk9IwDVuFI9VCdI=; b=CBPpSCep4ke/hCBqa727Ot09a8/bdCZR+WDEtSbPz/KuL7Bd69YqOhI2cd5urW+QoT UeB+VXyE86x1DSh3FGXx1+/bTidu0lIpDU492f0lcS3hYqGC8Nwe+KZRw4gRXRp+PUeM N1xrobayyFT4Qva1+2vgmFzVR0ddxxAon+OQd9JSipLrywozMVFftPOvpgeg/gc8haFP TvpdNpqtZ+pIBsCNhsNHUV7aGEVPtnY1wtaRCLUJWIuJ6eFDM1V1UyWmUmmPXgi1QgWJ iXrMFkzb5WT1Drgk3cUOV/tBQbaiCxBVO7kR2WPSFIQ8EGnnlcFN49sd0/Dj8KXuLfWi eqpg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q17si5078584ilj.42.2021.08.14.07.08.19; Sat, 14 Aug 2021 07:08:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238615AbhHNOGR (ORCPT + 99 others); Sat, 14 Aug 2021 10:06:17 -0400 Received: from smtp04.smtpout.orange.fr ([80.12.242.126]:60256 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238608AbhHNOGQ (ORCPT ); Sat, 14 Aug 2021 10:06:16 -0400 Received: from [192.168.1.18] ([90.126.253.178]) by mwinf5d27 with ME id hS5m2500A3riaq203S5nHk; Sat, 14 Aug 2021 16:05:47 +0200 X-ME-Helo: [192.168.1.18] X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sat, 14 Aug 2021 16:05:47 +0200 X-ME-IP: 90.126.253.178 Subject: Re: [PATCH] checkpatch: prefer = {} initializations to = {0} From: Marion & Christophe JAILLET To: Dan Carpenter , Russell King - ARM Linux admin , Leon Romanovsky Cc: Joe Perches , Dwaipayan Ray , Andy Whitcroft , Lukas Bulwahn , linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Julia Lawall References: <20210805104353.GD26417@kili> <1b94e688-a070-998a-3014-96bcbaed4cae@wanadoo.fr> Message-ID: Date: Sat, 14 Aug 2021 16:05:46 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <1b94e688-a070-998a-3014-96bcbaed4cae@wanadoo.fr> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Copy paste error, see below :/ Le 14/08/2021 à 15:59, Christophe JAILLET a écrit : > Hi all, > > Le 05/08/2021 à 12:43, Dan Carpenter a écrit : >> 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 >> --- >>   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); >> > > [1] and [2] state that {} and {0} don't have the same effect. So if > correct, this is not only a matter of style. > > When testing with gcc 10.3.0, I arrived at the conclusion that both {} > and {0} HAVE the same behavior (i.e the whole structure and included > structures are completely zeroed) and I don't have a C standard to check > what the rules are. > gcc online doc didn't help me either. > > To test, I wrote a trivial C program, compiled it with gcc -S and looked > at the assembly files. > > > Maybe, if it is an undefined behavior, other compilers behave > differently than gcc. > > > However, the 2 persons listed bellow have a much better Linux and C > background than me. So it is likely that my testings were too naive. > > > Can someone provide some rational or compiler output that confirms that > {} and {0} are not the same? > > Because if confirmed, I guess that there is some clean-up work to do all > over the code, not only to please Sparse! > > > Thanks in advance. > CJ > > > > [1]: Russell King - > https://lore.kernel.org/netdev/YRFGxxkNyJDxoGWu@shredder/T/#efe1b6c7862b7ca9588c2734f04be5ef94e03d446 > > > [2]: Leon Romanovsky - > https://lore.kernel.org/netdev/YRFGxxkNyJDxoGWu@shredder/T/#efe1b6c7862b7ca9588c2734f04be5ef94e03d446 https://lore.kernel.org/netdev/162894660670.3097.4150652110351873021.git-patchwork-notify@kernel.org/T/#m3424d6e97ef0f0ddd429cce3369a6da0ea9af276