Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp61647ybv; Wed, 19 Feb 2020 16:25:36 -0800 (PST) X-Google-Smtp-Source: APXvYqyosJe60O9dg0w1teU7zXL/Q/sjqVdtZYdX49EzA2L/yIqayx6U3l1vYaC3ESvrecOS80he X-Received: by 2002:a05:6808:251:: with SMTP id m17mr221397oie.15.1582158336637; Wed, 19 Feb 2020 16:25:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582158336; cv=none; d=google.com; s=arc-20160816; b=mISejzFlqXhQamknMR5pPhFrbGnp1XKcKAanATgyngiVRGt1KBzgeMD+v9dbd4eKva ObDqVVY2zsNv8VFYCbbUlMjvKMm2sJXGWAbZfxECM3umfv8jQND9URPM2iufChLC8PDN L4q3Q/iTbnYfdHlshSxR2TPx0u0FAshMprSN/ijgrzGl69wtuHOHWwFjN9m7D6ZUcCvU zi7DJeuWF8QL7R2ZJJREDYPfe7OSWOPkZfNz72P17ig9RZ7quZjPh2RqO07VkR8wKTz8 cHap5Y8lsh48LUiyVl2vs2t5cUUoN+nVp815w4mBU6rz2lg0gxNnbp2SxAWPpAvIWLsK KzWg== 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=MjxowEfRYuYh351YdASLXYLtM2KLiNoE6XBhm/ArwYU=; b=VwnQ4eC6zex0qboXNYO5mq57NQ8VA4ycJDxe/KRw2ku1XprIRyFt3qfTmkpxeLJkvY /rY36D2AGMq2+5/oC5T/C1ebqGbd0/aQLVMKbIusRndx+cS9PQ6ClUA4iMM9jh0OPVJ/ PzLg7Lc2HP1Hgl7unpYRKgqjLeMPlk6po+57PS3SM2D/LVR2ysWHHOPrVrafjmVZEnUy L3oAePiG8cTSz3yHMRs0A/fUbI1N4Nfhiht61FcVW1lmE1DDeyGCPRI4CEc9LAI5ZVah caNfPQ3AHpZE/vmy7JX/jg9xr6UgRIwsqut1f+cK2FeD0x63i271Gc463AS7VSauApLK ojIA== 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 l9si695179oti.229.2020.02.19.16.25.18; Wed, 19 Feb 2020 16:25:36 -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 S1727107AbgBTAYj (ORCPT + 99 others); Wed, 19 Feb 2020 19:24:39 -0500 Received: from shards.monkeyblade.net ([23.128.96.9]:49464 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726613AbgBTAYi (ORCPT ); Wed, 19 Feb 2020 19:24:38 -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 50AB415BD7A46; Wed, 19 Feb 2020 16:24:38 -0800 (PST) Date: Wed, 19 Feb 2020 16:24:37 -0800 (PST) Message-Id: <20200219.162437.1760861676179923216.davem@davemloft.net> To: gustavo@embeddedor.com Cc: jiri@mellanox.com, idosch@mellanox.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH][next] mlxsw: Replace zero-length array with flexible-array member From: David Miller In-Reply-To: <20200218205705.GA29805@embeddedor> References: <20200218205705.GA29805@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, 19 Feb 2020 16:24:38 -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: Tue, 18 Feb 2020 14:57:05 -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, thanks.