Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1016744ybf; Fri, 28 Feb 2020 12:09:33 -0800 (PST) X-Google-Smtp-Source: APXvYqzLbQtnCMqIyk0gfyMLiidCT+ujrz2CT3G5YNklbB6mvgdvDG62lcWyIxYvf9S3CMSo2qLx X-Received: by 2002:aca:1b17:: with SMTP id b23mr4431180oib.95.1582920573487; Fri, 28 Feb 2020 12:09:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582920573; cv=none; d=google.com; s=arc-20160816; b=tKVo5TGzSHpr3IJf8hLMRRl4TI98LZztiVlEv53FyHB8b6T3cRrz7JV9ZmLDY6yMgt +3i5hMKivOOxrlihsM36BJFmZ08OjPhfkIf4o6g58Q0yC1W6vbiRFKSOpOcUEWrY9gJZ TC5f8POEOJ1LzoYBvCQX/C2jwJ+7cKGqSWxeG+UIk0e3ndsMV4THCEWJ1mLEAPsV/m/f Yfbn8u5pK+9SP+76gZzJNe9WFQHm216cqPikzPG3E4BmB6qg/luXemXA5FK/Oc/ZApKp eiBCqIO3oktALNQLTRJ2pgfvUnt2QJxawbYi/jKOrIL2sQbZEEG165GXsrBC91W69xTn NsMw== 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=AllWJgB+SeZjhzqFSv1ttWMHMUYyy7w5kWMx1tWwnpw=; b=f0M/9YHu9uubgE+1xMzKQ86Jo393lvps249a1yvF3RcyR+vA1UnJVze7SZM3oMAWDn SHV6pBzJxNFzpH/GlS/ApbYW2goMpr344UQXpdS3Flxruc3MtHIxFf9XPkVl5OiZtCjL LT7Z2YAK9H6HM7kczQHAMgDx76AKX9krWjt9CO2Ge/q4o2+EmPaS3/SvSl/bX2QEKRKK ZjX4tjLZo+w64L4I3BK9pTT0OTIFN2muQGJGyHMxZsMrNJlPpjanAu4uYDk88ugnNsbG PGu3Pk0VUcarPqfk5f73I4DsHjZ4EAt8xIZnLO/jxVdmBVmPeACNAshD5haIbjLKT7dy Ihfw== 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 r6si2132312otp.220.2020.02.28.12.09.21; Fri, 28 Feb 2020 12:09:33 -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 S1726892AbgB1UJQ (ORCPT + 99 others); Fri, 28 Feb 2020 15:09:16 -0500 Received: from shards.monkeyblade.net ([23.128.96.9]:55774 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725730AbgB1UJP (ORCPT ); Fri, 28 Feb 2020 15:09:15 -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 17F7F15995574; Fri, 28 Feb 2020 12:09:15 -0800 (PST) Date: Fri, 28 Feb 2020 12:09:14 -0800 (PST) Message-Id: <20200228.120914.1370425079281188005.davem@davemloft.net> To: gustavo@embeddedor.com Cc: bjorn.topel@intel.com, magnus.karlsson@intel.com, jonathan.lemon@gmail.com, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH][next] xdp: Replace zero-length array with flexible-array member From: David Miller In-Reply-To: <20200228131907.GA17911@embeddedor> References: <20200228131907.GA17911@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]); Fri, 28 Feb 2020 12:09:15 -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: Fri, 28 Feb 2020 07:19:07 -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.