Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp53469pxt; Thu, 5 Aug 2021 17:44:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyF82hut0fTkJ0ndbHH7B/ykKxco5qrQgV50SrhSSDWXjNUbEAXlMai89jtTeMpqrrpVBgP X-Received: by 2002:a17:906:68db:: with SMTP id y27mr7241071ejr.403.1628210646676; Thu, 05 Aug 2021 17:44:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628210646; cv=none; d=google.com; s=arc-20160816; b=QxQSPs1pxgRYqqnzrEt9fXvy+h8VKOdvI0fLZbPW32brVXfbPLQ0LUwY15K0Pk/rNy lZTlPQjhONNrX0FueyhjcYGMNodvDxEvaUYuSKoucB6GWqDgcIEpeSLPXiHEBpKMTN4m LTT60q4eOnP6aLtx+gwzFt1lcK0+1xZY7zJRWhy1jde1BjaynKWuTfB9WE0L/NkumrSz giDgEUHOql/n+aAdSBvu9aEgbw6KRuZBDlgbEx2uC1g8u28GVzeHp4812GAFN4Bs82qR T3vealhbyCIqhLttrRB0doNCPFG953c6oRN5aVQpds+my+V4Onw97Mn4lR/oYIkDBc4o FqkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:ironport-hdrordr; bh=wX+LtpaJaxjCqBng9O0IMHyONjInJ7p6MoxuHRV8lEU=; b=CxMLLI5fH8svhjCDwSqqF4EAkK48KHvwSCuaw20XKlJ8UVrfTzzTATKJ0Qs/CXlVkV /ZdtQBn9AyG2GOhE4M+/Sca/o+8dXeL4yw4HJ8xbbjRgg8ki3DpEDso6vdgym4K4BgVH HETOV6s9XxbCg5u8U6qR5HGBIWOaE5x/mRfw1wn1aPOsk8D8MOBbRpKfvroGfOdVItr0 +c+oQL5JJC2FBzMN0nzwC8KwIn/YQnXLowmsVlCdCYWwpDlulmVmbJMZWcFlavX7rVgu oq5WGe/mUfYIOo0UEj4Nz0zvaAK41kEtXsjXmUFxvRXTp0eJktq0eUU33ps7VDLv7BIp r09A== 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 s18si7810512eji.591.2021.08.05.17.43.44; Thu, 05 Aug 2021 17:44:06 -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 S241624AbhHESow (ORCPT + 99 others); Thu, 5 Aug 2021 14:44:52 -0400 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:22754 "EHLO mail2-relais-roc.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241592AbhHESou (ORCPT ); Thu, 5 Aug 2021 14:44:50 -0400 IronPort-HdrOrdr: =?us-ascii?q?A9a23=3Ayn/lL6Ff6gNM5rP5pLqE+ceALOsnbusQ8zAX?= =?us-ascii?q?PidKOHlom62j5qKTdZsgvyMc5Ax9ZJhCo6HiBEDjexLhHPdOiOF7AV7FZmXbUQ?= =?us-ascii?q?CTQr2Kg7GM/9StIU3DytI=3D?= X-IronPort-AV: E=Sophos;i="5.84,296,1620684000"; d="scan'208";a="522913201" Received: from 173.121.68.85.rev.sfr.net (HELO hadrien) ([85.68.121.173]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Aug 2021 20:44:34 +0200 Date: Thu, 5 Aug 2021 20:44:34 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@hadrien To: Joe Perches cc: Julia Lawall , Dan Carpenter , Andy Whitcroft , cocci , Dwaipayan Ray , Lukas Bulwahn , linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH] checkpatch: prefer = {} initializations to = {0} In-Reply-To: <83ffab14de1c2af00d38d532ffecdda1f9e936ab.camel@perches.com> Message-ID: References: <20210805104353.GD26417@kili> <117021b44dc9ba570a0f48736d14a267a8701d0a.camel@perches.com> <83ffab14de1c2af00d38d532ffecdda1f9e936ab.camel@perches.com> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 5 Aug 2021, Joe Perches wrote: > On Thu, 2021-08-05 at 20:17 +0200, Julia Lawall wrote: > > On Thu, 5 Aug 2021, Joe Perches wrote: > > > On Thu, 2021-08-05 at 05:27 -0700, Joe Perches wrote: > > > > On Thu, 2021-08-05 at 13:43 +0300, Dan Carpenter wrote: > > > > > 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. > > > > > > Perhaps a cocci script like the below could help too: > > > > > > $ cat zero_init_struct.cocci > > > @@ > > > identifier name; > > > identifier t; > > > @@ > > > > > > struct name t = { > > > - 0 > > > }; > > > > > > @@ > > > identifier name; > > > identifier t; > > > identifier member; > > > @@ > > > > > > struct name t = { > > > ..., > > > .member = { > > > - 0 > > > }, > > > ..., > > > }; > > > > My test turns up over 1900 occurrences. There is the question of whether > > {} or { } is preferred. The above semantic patch replaces {0} by {} and > > ( 0 } by { }. > > I saw that and I don't recall how to force one style or another > to be output. If you remove something and put it back, then Coccinelle takes care of pretty printing it. So the following produces {} everywhere. Fortunately Dan seems to prefer that... @@ identifier name; identifier t; @@ struct name t = - {0} + {} ; @@ identifier name; identifier t; identifier member; @@ struct name t = { ..., .member = - {0} + {} , ..., }; julia