Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp470681ybf; Wed, 26 Feb 2020 16:46:51 -0800 (PST) X-Google-Smtp-Source: APXvYqy/ej9nUkEWggxhxJdr/+GK5RhXY4FskpyhONi7kFN9dm39U4hMZEGvt1HEqy4kl6TBljdS X-Received: by 2002:a9d:6c9a:: with SMTP id c26mr1187963otr.279.1582764411563; Wed, 26 Feb 2020 16:46:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582764411; cv=none; d=google.com; s=arc-20160816; b=hMaEfjwVCJI0u+xOSbgc4XOGDsCq1Nf+vL4EtDtNi/Aywcm8CFK2j72nASY9POdWFi DYtIvtigGQDnOac/Y055K6y13pY2U99iwDDClR1UIL1qV/YdSujPQmvewsjpcn/8GKDk /q/8DwX+s/nCdu+KNmvOyY6c3cAJwnD25XE/hddVZiebIoUpoDXwIz+LPKukEcIzUrbu gbWmnWoWJFcSRJK+PIOPLMkZdaZ/Yw3h04UFeLmpTli8GCctPcdbi32efRi3xeqdRLDA G91Xa4yfqATDx5u5f6ClJuJtEdIuESeJP6uNPHdo3QBrxWwR8yO7Jx+keqQoT4cWKgWl yvDw== 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=mztWuXLpVbpL7bxCs9W4J+qW5K/dHZuJ9CgkcJt3kGM=; b=DJvy4LYVxhdYkDaZqDZBwTyLvUzpXnlYWo157gXhzyeX1sXnt9W0jiBJ06PLTW10B2 pPHO7yTgCdzN7JrEEdMo81MrcdoC8zCdnD0+cZkYcKn95GNUyCyNB6bQSg1DpRpNZHdJ xqPT9WXFMrmK98GlfPPfMhtLf8AJb54aYtQAOG1SBRSU99gEbLTYEMnfAE7ZP5wMPMFf 3/4sCIvd86n5AS6GhUClLUcnLdbA0YtaQiAdxuBbLPLt72JGO+rSJEQGCkBGKQNve8Yf nLC8RNd4lK/nd4bSZO9qiJwFVS9SAvzo3rcO3GqO8GA2LgakMdK1O9IKHHxLEd+mivt7 8Kyw== 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 v14si630738otn.293.2020.02.26.16.46.40; Wed, 26 Feb 2020 16:46:51 -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 S1728183AbgB0AqT (ORCPT + 99 others); Wed, 26 Feb 2020 19:46:19 -0500 Received: from shards.monkeyblade.net ([23.128.96.9]:35424 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728165AbgB0AqS (ORCPT ); Wed, 26 Feb 2020 19:46:18 -0500 Received: from localhost (unknown [IPv6:2601:601:9f00:477::3d5]) (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 5D21215ADF45E; Wed, 26 Feb 2020 16:46:18 -0800 (PST) Date: Wed, 26 Feb 2020 16:46:18 -0800 (PST) Message-Id: <20200226.164618.773719496125589787.davem@davemloft.net> To: gustavo@embeddedor.com Cc: linux-net-drivers@solarflare.com, ecree@solarflare.com, mhabets@solarflare.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH][next] sfc: Replace zero-length array with flexible-array member From: David Miller In-Reply-To: <20200225000647.GA17795@embeddedor> References: <20200225000647.GA17795@embeddedor> X-Mailer: Mew version 6.8 on Emacs 26.1 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]); Wed, 26 Feb 2020 16:46:18 -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 18:06:47 -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.