Received: by 2002:a05:6a10:c7d3:0:0:0:0 with SMTP id h19csp313325pxy; Sat, 14 Aug 2021 07:40:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwav+tJOx6SoU+R+aXDimj+thCXmocxeZQwlHX3af05EDfJ9E0IHTgFzGZQMSG9Rw5kID6F X-Received: by 2002:a05:6638:303:: with SMTP id w3mr7070188jap.79.1628952010031; Sat, 14 Aug 2021 07:40:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628952010; cv=none; d=google.com; s=arc-20160816; b=CmnAcpbpz7vSQTBtryI4Yi9+N5s/le/nnC+117PHSuD2dorw+SopsbeN6+qgY/xDDG MuE7QBqcVgkU3PLj4ireUQcSw2b0DRxgz8JK0tSQyIoS6GDG0j5NIjUQWP+4ZfNduozi 7c2dva04nluwgIxl79i5JNNZSh196R0QObAXJcgOOwvQfixeJ2fiQKr6qPNc7rI4H6dD g2oI851jVEk/v0XFC9eSs2+/001dKWuvr5iQ4anb10Aothq/NrrLd5kXDSbg/sjAqbbH 3qUzHaeEmZECTMDU/cYYRLYdshC/9u3HLjGM1BrWYOJJcCrSZ0V4P/lNhVMj7VREOG+1 DWUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=xiv2sV5mVnGxUGJZQuLGs/Z+kmY4NDSrqfPv626IOro=; b=YcbKUGwFOK7PhlgADAiW9YEj/y8HRrJTMY/8yddAQXwEIkW2BJkVTRrMS3kXiwkw37 1VKwjhn1/Ec1gMOvKe8iV4WigL4z4G4EWHWRkTL0OxToOygKTifpBCX/RwaQOvsT+A+x uiz1Z9dHAoWVLXkWhTAril8ff/X6jzYyNfhQKNx85oEusBjqeJPnn7rHHWDo5s44C26j jRDlqugYMxLS1KgFcdSlW4vqqtz8IE4KmDTixPyTg1YzIvUUYcB0yreNAi4aqZPoqlGd CDdUtaqLD//Nj+AUD1ksZYitZKaHQ/+74hz2UMgacIMexHpaoW779QjcwYnaOCR7Rwzs m/Bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hHx6kQbU; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g7si172335jar.3.2021.08.14.07.39.54; Sat, 14 Aug 2021 07:40:10 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hHx6kQbU; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238615AbhHNOjA (ORCPT + 99 others); Sat, 14 Aug 2021 10:39:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:49430 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238512AbhHNOi7 (ORCPT ); Sat, 14 Aug 2021 10:38:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AAE2D60EE2; Sat, 14 Aug 2021 14:38:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1628951911; bh=uL6AX/4t+TzWi7LocyAGDouPiMye3Z/PsKFJKjjEim8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hHx6kQbUH5M7bA5oE8fZP5jN/HxVGlyPKVAa1qnr9YH4F2V1GCwEwTXNx6p/jTVq7 feKxC2eXe3n2n4fLMKFAxxw5hGH/3AIKmAvEjfEbodaLao2xJxxzMR/+M8hHouj8tV J77XoAfRT53GiSLdfSjtOZerSriWeu2e59kdqHG35COBJz84uhIgi/M4GQLhg8SHcL aDWznza8M26KN7uB8yq/c704W35y0ZHpvY/+CrrZ5CwCa4pqyjlJNhYQcIbZQRoAS3 ZR3UtHxNTrJsHtQbTYyFUYPp/EILOT5+yyR9MLplLkmcPSs0Tsx3QESLD8GMdxUp4X XHE357aMkFEeg== Date: Sat, 14 Aug 2021 17:38:27 +0300 From: Leon Romanovsky To: Christophe JAILLET Cc: Dan Carpenter , Russell King - ARM Linux admin , Joe Perches , Dwaipayan Ray , Andy Whitcroft , Lukas Bulwahn , linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Julia Lawall Subject: Re: [PATCH] checkpatch: prefer = {} initializations to = {0} Message-ID: References: <20210805104353.GD26417@kili> <1b94e688-a070-998a-3014-96bcbaed4cae@wanadoo.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1b94e688-a070-998a-3014-96bcbaed4cae@wanadoo.fr> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Aug 14, 2021 at 03:59:22PM +0200, Christophe JAILLET wrote: > 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. There are number of reasons why you didn't notice any difference. 1. {} is GCC extension 2. {} was adopted in latest C standards, so need to check which one GCC 10 is using by default. 3. Main difference will be in padding - {0} will set to zero fields but won't touch padding, while {} will zero everything. > > > 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