Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2966793ybv; Mon, 24 Feb 2020 15:27:11 -0800 (PST) X-Google-Smtp-Source: APXvYqxSLUfpODWR5zKR8/+yp/NF8rYAyFCXgKiYgpbBe+r3Y3qgu1hG/79q9mjTGmSDlCEWCjE0 X-Received: by 2002:a05:6830:4c7:: with SMTP id s7mr41580143otd.359.1582586831120; Mon, 24 Feb 2020 15:27:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582586831; cv=none; d=google.com; s=arc-20160816; b=NrHmwaiBti9jUEsq8Wo9ZtVi+PQWC6clC42x3IOLgZ4Y4gAHCthLAt/RDsT+9AKBNc rztiT5fw/qs+cpcqcNiMhi3D/ilg6eKMztzrtFRebbQpjF+Cb7vhBB0BVa9POzDLzBPo 6ASixbDCohMG7imtL/wx0E3+rajImpO5OZrzo9XuoMxSCRueU+Mo6mJ7J1bSwYeXaJiV UfD6r2To7K54SLbbIlCPfFTsMpXjq11frcojHKuC7tRklo1jQFSIoRXeXCh9w5pipgZT zkqdDEYgwWdqEF1DY3y/S8C8m81zzSx92a2Tp6H0Zn84idPTjTuPQaxObi0bpdqle5/4 FFsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:from:subject:cc:to:message-id:date; bh=yC+AzKL5a3AOw/W308WNq/k9V+bfV3igjxNRRPRn/Ew=; b=NCffnpYkVlFOhecHwYKKYJzwryioGrDJ6iVr5lGMz9pD6mUnAUF/7x3kjBnNpMI/RA TQCX9nr0fdIUqvHtt77e08CA3J2zUnG9HcqDIyf3o7xYSXABxnsKo4TdCz/X887ZJNnh HlE0fLSmDbZh71hyCM6E5wOHexovzlpY+JVU5MkWKlVdie+jN1OrfArHt61IL7ZniCse ghdebOL4MwppcKGGyJstH4UyTUKqYUD28I9MgdRSU89VqNQAX/XpelDQiHcEk4bb37KZ HK42Tk6l3aIac7ZYlyqQpkA7uV9u4upyVZsyZkwsR/F5rXWC+niH0Me88pJfHjXp7vUW tPOQ== 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 k184si6319180oib.239.2020.02.24.15.26.58; Mon, 24 Feb 2020 15:27:11 -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 S1728432AbgBXX0p (ORCPT + 99 others); Mon, 24 Feb 2020 18:26:45 -0500 Received: from shards.monkeyblade.net ([23.128.96.9]:40022 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728226AbgBXX0o (ORCPT ); Mon, 24 Feb 2020 18:26:44 -0500 Received: from localhost (unknown [50.226.181.18]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) (Authenticated sender: davem-davemloft) by shards.monkeyblade.net (Postfix) with ESMTPSA id 034AD124CE3D1; Mon, 24 Feb 2020 15:26:43 -0800 (PST) Date: Mon, 24 Feb 2020 15:26:43 -0800 (PST) Message-Id: <20200224.152643.132900697461169268.davem@davemloft.net> To: gustavo@embeddedor.com Cc: geoff@infradead.org, benh@kernel.crashing.org, paulus@samba.org, mpe@ellerman.id.au, kou.ishizaki@toshiba.co.jp, netdev@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH][next] toshiba: Replace zero-length array with flexible-array member From: David Miller In-Reply-To: <20200224163252.GA28066@embeddedor> References: <20200224163252.GA28066@embeddedor> X-Mailer: Mew version 6.8 on Emacs 26.3 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.12 (shards.monkeyblade.net [149.20.54.216]); Mon, 24 Feb 2020 15:26:44 -0800 (PST) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Gustavo A. R. Silva" Date: Mon, 24 Feb 2020 10:32:52 -0600 > 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 Applied.