Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp935577ybf; Fri, 28 Feb 2020 10:27:28 -0800 (PST) X-Google-Smtp-Source: APXvYqwZpbDDdPvTQ46l4VBMbBXFaTPP+6fbYQfW8ZUb3ouF1fFLeSCGoPcMApq+yeAc3+vwI+kA X-Received: by 2002:a54:4595:: with SMTP id z21mr4179700oib.136.1582914448106; Fri, 28 Feb 2020 10:27:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582914448; cv=none; d=google.com; s=arc-20160816; b=pHks8/4ONfPhaSP7mlkF2mXOetndtVG1BfmwoiVITxQnUCXdL0zhfRjPWqMZI+NGjT nCv5pPVmTou4ySMQqTszxdATFXFd7NmnDfUkXZC8Xp4twpGgdvYUD9TF5ObXjVbC0i1e wOhYGHzLmJFeiAINvwrtO/TvwuFQPUCc5wQuCN46/smNUtCmi/goV6uWaP7hMusFGAD0 U2qqTmumBcOGv1ZKFJGTeTa7B1k0krqAwaRhQ6eJ2BaRjbsqd8x1rAis+lIufW1GxxPm MX2qTeW0nor/LkCZrMKtzX7xpNVOxgKqDyjqVOBvX0ooP4TmcvnDw1OQc7ODZtS0FMHR g1Ow== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=oaio+vwTHMWfhSFuwUMTY3g6+CWkVUbr9Eao4gH524E=; b=ibGQsNV5awx2LaqH7OqCDrGKXvLXvZKLGxBQRR612ENaUdDuYjEFkNCNYuwhafqzKl vsrhBYH1DXYgdqbtLVU3WhBCbCbsDWwAE4wtGP7zX+IutB98/JidF5EJBMzT7g2lBnzI o8Sw6VRT2P6Kg6Jy73/PKzYLujpqwDtXJh1bhPXpQ6lQFKunySY7c4p3mvJEfMh93v1Y Zj4VXfFx2JewRt9NCmoOIn6ePf3q/pqYO5t89z/Nn3WLc4DSiJe9MmfWBP2YqfUxhKOT Gc3KpUZbEuPl17Gg5wHk9hgZDqAfXfc3T+heaoxtkXJBkPxwd3H1omPPbOS+jjTW3Bn1 HJpQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w4si1985809otq.144.2020.02.28.10.27.16; Fri, 28 Feb 2020 10:27:28 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726980AbgB1S0N (ORCPT + 99 others); Fri, 28 Feb 2020 13:26:13 -0500 Received: from mga05.intel.com ([192.55.52.43]:61875 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725877AbgB1S0N (ORCPT ); Fri, 28 Feb 2020 13:26:13 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Feb 2020 10:26:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,497,1574150400"; d="scan'208";a="231166116" Received: from rdunst-mobl1.ger.corp.intel.com (HELO btopel-mobl.ger.intel.com) ([10.252.40.10]) by fmsmga007.fm.intel.com with ESMTP; 28 Feb 2020 10:26:10 -0800 Subject: Re: [PATCH] [next] xdp: Replace zero-length array with flexible-array member To: Jonathan Lemon , "Gustavo A. R. Silva" Cc: Magnus Karlsson , "David S. Miller" , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org References: <20200228131907.GA17911@embeddedor> <6FEAF24E-27CF-4840-8134-595D27275976@gmail.com> From: =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= Message-ID: <4f7c8a2f-e49e-beb5-9188-1bebac804d8d@intel.com> Date: Fri, 28 Feb 2020 19:26:09 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <6FEAF24E-27CF-4840-8134-595D27275976@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-02-28 18:14, Jonathan Lemon wrote: > > > On 28 Feb 2020, at 5:19, 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 > > Acked-by: Jonathan Lemon > Acked-by: Björn Töpel