Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp7185419ybf; Fri, 6 Mar 2020 12:04:35 -0800 (PST) X-Google-Smtp-Source: ADFU+vtxu3p6kgApP70GxmKZ26DWnNuIUeYH/rmK+54Ul9XqsVv8aTicpjtFpbAeubc7HFHayHLt X-Received: by 2002:a9d:6457:: with SMTP id m23mr4038146otl.162.1583525075763; Fri, 06 Mar 2020 12:04:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583525075; cv=none; d=google.com; s=arc-20160816; b=qGskJM516sSGyBrLLLvCC4rS8K9v2OvOOqZapyKpeRz0kgBnwY1v0MHhIcucZwvsfb Yo6VkyEnJaARvtVAacssVS7S+z6HF4u563nJoXLLawDzde/Xf+h/0VHGDHd8d6QwwOCH QSA1lNuKikG+XTuylhJ/0Te33b2h8nJ1rYGpJFwmexcx/AbgtgL2AjoOIQx4s2HRYBbr O5QfEVt2ShJm3dTfe0qic2ypOsrrWdi6ObhRo8CswaNL5lBvl/8DMRBHfpE+wXPOLVmr 7PlKcLMimtyDzeAom02WH2uG23EY84H+Yohz0TtVPCSntY5zJ7EqufqlxsgLuG8W1anB PASw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:mail-followup-to :reply-to:message-id:subject:cc:to:from:date; bh=OIa5jyBlPQzGsngtLbwyr8CIXJFOF7JU4lJ2cDiNegE=; b=C/Ljn0A+ePLAoC0w4sE0vYxdz8f9yAUHrjPF7HtuMRzVmd1NxuNu0dnOm+aMhD9Ucw yd+wA/075Q1VBC9org6BUb8IgXabuXWDSpizdRGdtUHRbMCEgAhu4wUWOes3uWS4aWrf 4APWAKb/vsh82u60jN2jEEYcqVrTziA7+6n/cV0Gx7FbFc5VColL/X+UHVOxat77qg0t 5RuPt+yvnewH+zkbzi/hrGUZPCHh5fy2KF9qwWbDESjcI3qGJem1RMHjwC4Kx0IrPjyP n6l3d1yfkQ1YOUl77LML73grVbpfUsrtS3Wg4CfpAbCpTFgMK68S7/wV1NmD8UVB2XJ4 rUSA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 73si220395oii.60.2020.03.06.12.04.24; Fri, 06 Mar 2020 12:04:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726533AbgCFUCz (ORCPT + 99 others); Fri, 6 Mar 2020 15:02:55 -0500 Received: from mx2.suse.de ([195.135.220.15]:33178 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725922AbgCFUCz (ORCPT ); Fri, 6 Mar 2020 15:02:55 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 158AAAAB8; Fri, 6 Mar 2020 20:02:54 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id CE2B4DA728; Fri, 6 Mar 2020 21:02:30 +0100 (CET) Date: Fri, 6 Mar 2020 21:02:30 +0100 From: David Sterba To: "Gustavo A. R. Silva" Cc: Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH][next] btrfs/rcu-string.h: Replace zero-length array with flexible-array member Message-ID: <20200306200230.GK2902@twin.jikos.cz> Reply-To: dsterba@suse.cz Mail-Followup-To: dsterba@suse.cz, "Gustavo A. R. Silva" , Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org References: <20200306165105.GA22637@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200306165105.GA22637@embeddedor> User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 06, 2020 at 10:51:05AM -0600, Gustavo A. R. Silva wrote: > The current codebase makes use of the zero-length array language > extension to the C90 standard, but the preferred mechanism to declare > variable-length types such as these ones is a flexible array member[1][2], > introduced in C99: > > struct foo { > int stuff; > struct boo array[]; > }; > > By making use of the mechanism above, we will get a compiler warning > in case the flexible array does not occur last in the structure, which > will help us prevent some kind of undefined behavior bugs from being > inadvertently introduced[3] to the codebase from now on. > > Also, notice that, dynamic memory allocations won't be affected by > this change: > > "Flexible array members have incomplete type, and so the sizeof operator > may not be applied. As a quirk of the original implementation of > zero-length arrays, sizeof evaluates to zero."[1] > > This issue was found with the help of Coccinelle. > > [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html > [2] https://github.com/KSPP/linux/issues/21 > [3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour") > > Signed-off-by: Gustavo A. R. Silva Added to devel queue, thanks.