Received: by 2002:a05:6a10:c7d3:0:0:0:0 with SMTP id h19csp290301pxy; Sat, 14 Aug 2021 07:03:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfitIMtVhFjTiRvAjEGbuRN4xH+STqg0ckc6w1hb5Ga0Wupdxrr8/uz1MS0DzRPTOSyCUy X-Received: by 2002:aa7:d05a:: with SMTP id n26mr9350096edo.272.1628949831959; Sat, 14 Aug 2021 07:03:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628949831; cv=none; d=google.com; s=arc-20160816; b=Wp2iaScJAzAkmuxZl2pmsaOez0mVBX6M8sLUAWEjTNf/SMx8y/pJNgPFK0OiCCw4RN ZpXFpcxV00V92euH6P2JrqC59CXo+j3OCietBQRJCKrMng7n8ZTKaoGViHq9ZmRg2ULp Q3WUPsxGhK2oPvPIiA/LnoCWZh0u9zq4jz7W7Mi3RosD6MoZsyU8MeVJ81IzYwU5euE0 tkd6mwJTctFhb+9oxFszQuZIrLVdlq6zmep97efSw0yVGia65hZmJ28hlpNQ2qnlTej7 PUdQu6pLcJlZdKizIqyq/hLdD4lIRBZDTUTI8M5knvasfufvMqhC5RqI+Y2+wXtEAmDz 6n7A== 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:from:references :newsgroups:cc:to:subject; bh=w4ALXou918p4/PhWomZvc7OvdDP8rxacQw2RIoHvP78=; b=VfJStNLUM1RSsXdUElevuRlqhZQ9z2HVVE7OYm97fvKSMXfhGd2kdU6JnPZFXLYdgx 0QevodD2DlQBcGJyUuswqONUK06Kr0d5aSn/YiccUqHDxI9wlo61bu0bhpBbaiXCARWK 3MuSVNKLDF9JmdsH7dtRttDizTIgRYjqM66bQK9Qm4UFjs/7lypE4ECatwm7SiYYbYvc Wp7piQyNQw5kOEXucSgASfHzbZLala9B+tiUpMzGC05JIGqDWhSVSFo9ja0vpslFY6z2 s7aCpJ11psCfu1ZDIpyv0DeakETxx7Ello5snJPWA9qGnF9qresWrgETFMS3C6aFLbsW YWwQ== 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 w24si4404135eja.172.2021.08.14.07.03.24; Sat, 14 Aug 2021 07:03:51 -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 S238385AbhHNN77 (ORCPT + 99 others); Sat, 14 Aug 2021 09:59:59 -0400 Received: from smtp04.smtpout.orange.fr ([80.12.242.126]:39087 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231956AbhHNN7z (ORCPT ); Sat, 14 Aug 2021 09:59:55 -0400 Received: from [192.168.1.18] ([90.126.253.178]) by mwinf5d27 with ME id hRzN250073riaq203RzNel; Sat, 14 Aug 2021 15:59:25 +0200 X-ME-Helo: [192.168.1.18] X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sat, 14 Aug 2021 15:59:25 +0200 X-ME-IP: 90.126.253.178 Subject: Re: [PATCH] checkpatch: prefer = {} initializations to = {0} 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 Newsgroups: gmane.linux.kernel,gmane.linux.kernel.janitors References: <20210805104353.GD26417@kili> From: Christophe JAILLET Message-ID: <1b94e688-a070-998a-3014-96bcbaed4cae@wanadoo.fr> Date: Sat, 14 Aug 2021 15:59:22 +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: <20210805104353.GD26417@kili> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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