Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4929283ybv; Mon, 17 Feb 2020 08:38:06 -0800 (PST) X-Google-Smtp-Source: APXvYqzJgz1UZMmvqVIOzO7fRGsew1Jc24InBcUl8+Fcl25fCips7aC33h1WLareNtOyxRzbM5b4 X-Received: by 2002:a54:4011:: with SMTP id x17mr10082496oie.35.1581957486324; Mon, 17 Feb 2020 08:38:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581957486; cv=none; d=google.com; s=arc-20160816; b=0OS2O9QodRKHLkY3OG5IQ2g2mE42cvb9ve0uPXX1ZcIbkp5HMhwAytuONVP0iONP6b qMiwvUr2VkiFW/9BTPYEL96NkQ65Fa62lSTrm3X3o7uPyMgk1ipzRUeqPqZ9YzGQTYuw SXepD7Iw8XIrrRpbXF7iSU57WpBLboX/W1Ds+KGRjqQp/NX1RC+CIjoJz2U+rHLWiDpy eC8FzWs8dN/0kleFm1do5+I/H3wXZGoUz11YHbg9sN94eQpdC2O+1Nya2TS7F0W0zRaE iC56DAZ613BuEHyOO5grm+mXQNCsTv6YTKN9kaC3AcFBI6vvrhWMp+Tu7RTLZem+gK9/ mnfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=U/DkhJe5t7eXXI1EVTHRhlZjbaCbNOzhvzQbpcTV3UA=; b=zr6xUWUFiyyMFTWqdjSfO5aCMOzhFWNri8r74SFCaJGsnKlIOMeCtOlJCWfwGcZ02A O2sM0umYfSqemf8IYa/CD788gR08AmCnmoOVtCPAE3RaGfl6i6KlQyTQXu9XEnmLgr4H msTtZzR7rcOIO/wm946LiE/p0PDsIvdgAYdgMFazVqZfX5srsbpQeAoaSbqHeCWilt+E NJCyq1SyAXIHLpT1BBH5lQxRZbPwBWv+KX/Kb3yFDkE+AThAD/MlvygOxBMXklihrvne M3GQVKRyaqphUR2HOzmHiDhmBTNXky91BdHolnNhIjlNTlzVy/GTJCBz9BGpXK6qNAh1 nGfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=W1sUl7c1; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i20si369311otk.270.2020.02.17.08.37.53; Mon, 17 Feb 2020 08:38:06 -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; dkim=pass header.i=@kernel.org header.s=default header.b=W1sUl7c1; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729450AbgBQQgQ (ORCPT + 99 others); Mon, 17 Feb 2020 11:36:16 -0500 Received: from mail.kernel.org ([198.145.29.99]:39294 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729080AbgBQQgQ (ORCPT ); Mon, 17 Feb 2020 11:36:16 -0500 Received: from linux-8ccs (p5B2812F9.dip0.t-ipconnect.de [91.40.18.249]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B65502072C; Mon, 17 Feb 2020 16:36:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581957375; bh=NCQqIN5Kmoitt0UNkCbypXgsb9gcydB2SYQaWeUgi8A=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=W1sUl7c1cQL7SlIRcLudZhge4mF+BDZc6o7m5VLqDNq0T0hxuocdzMotgj0eMPRes ZuCGMChm96eImIzUmk7ef9dvIaMDu9A2ZVhkEwEzmg1FSYy0fiDVruRT2uuKwHAZDt 1Q5XR0ArLVmiXxm6SMbc0EIL/ebp9xkb1e869b5w= Date: Mon, 17 Feb 2020 17:36:11 +0100 From: Jessica Yu To: "Gustavo A. R. Silva" Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH] kernel: module: Replace zero-length array with flexible-array member Message-ID: <20200217163610.GA16560@linux-8ccs> References: <20200213151409.GA30541@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20200213151409.GA30541@embeddedor> X-OS: Linux linux-8ccs 4.12.14-lp150.12.61-default x86_64 User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org +++ Gustavo A. R. Silva [13/02/20 09:14 -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 Gustavo! Jessica >--- > kernel/module.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > >diff --git a/kernel/module.c b/kernel/module.c >index 33569a01d6e1..b88ec9cd2a7f 100644 >--- a/kernel/module.c >+++ b/kernel/module.c >@@ -1515,7 +1515,7 @@ struct module_sect_attr { > struct module_sect_attrs { > struct attribute_group grp; > unsigned int nsections; >- struct module_sect_attr attrs[0]; >+ struct module_sect_attr attrs[]; > }; > > static ssize_t module_sect_show(struct module_attribute *mattr, >@@ -1608,7 +1608,7 @@ static void remove_sect_attrs(struct module *mod) > struct module_notes_attrs { > struct kobject *dir; > unsigned int notes; >- struct bin_attribute attrs[0]; >+ struct bin_attribute attrs[]; > }; > > static ssize_t module_notes_read(struct file *filp, struct kobject *kobj, >-- >2.25.0 >