Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp677824ybv; Thu, 13 Feb 2020 07:37:13 -0800 (PST) X-Google-Smtp-Source: APXvYqzyWIDaXmxRzLKtI5VYhhq9gMlue4IStNIcBewfpDzIG0peWCunZO7ZpjMb/XqAgDOLG+KH X-Received: by 2002:aca:bfc2:: with SMTP id p185mr3418213oif.57.1581608233192; Thu, 13 Feb 2020 07:37:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581608233; cv=none; d=google.com; s=arc-20160816; b=VcGreP2dKDZ+NYQ5sc5W4LWMshechp3Y44GzWPn8bqUYGvcZZ9hHLRX1pcEVRq/yk9 5fzIsZC6C0T+79XMgUcsNoCRQ4kS7ZFaURZaC0a39kHrHKeU/+HG+OGYctCmmAfg31O0 O7HHRB0Of7ZWo6I0teJFCiGpD1C0he0gNsQIXXXGSoYGmWSsViv1EZ1I9pOeHnGmoz1/ gDbF76LDJJoULpfFO+x+2fKiNmYVG4bc0tGJLL3+WKfpLNil24iJvSjXnHGwOzZXbEs4 Nv0MCbDej/71Rnvp0fN9JeYV6gKCqRYAj+R5+JCfU2w+gSAYVqdT+1rXEsuzC3xX+Asy /iIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=mMH90DJQNFAtuTIHTFIPLDELcmZyic0yLac3lSYPFq4=; b=Cl5cN92m0DaW1J2oIjvral9GLTYqCk/fxRb4UJm24G+78y1vlQ8SexdTVlMffC5Jqg lsjC+HBOmXBliPeiUYFoyTbMxs7XjYYbBXSwPOesbR416slVnSw/qA+3ghI3Mku+CKuH 6ct4ZLvcKagDwNb3IB97JkpB+F9oN67BbDpOUJa0/XGNBtx65MdPhIRooC2L3LeVZt9s DfNJU+M9VhRHVGi2A8615cPYy8n371Lzlno8MSWh1TA9QOzj1Fte+M+rqWWZB6v3s28y Ihu2TwtbslQp0NaLQYVp7LG1nPN6gp/nY4Uz42h+VgmAuVVte5Mx53Rw9sHXv2jY/6aa 7QDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b=ImPLnHeg; 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 x198si1263321oif.108.2020.02.13.07.36.59; Thu, 13 Feb 2020 07:37:13 -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=fail header.i=@embeddedor.com header.s=default header.b=ImPLnHeg; 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 S2387416AbgBMPfx (ORCPT + 99 others); Thu, 13 Feb 2020 10:35:53 -0500 Received: from gateway20.websitewelcome.com ([192.185.54.2]:41631 "EHLO gateway20.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728602AbgBMPfw (ORCPT ); Thu, 13 Feb 2020 10:35:52 -0500 X-Greylist: delayed 1457 seconds by postgrey-1.27 at vger.kernel.org; Thu, 13 Feb 2020 10:35:52 EST Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway20.websitewelcome.com (Postfix) with ESMTP id 7CC8F400C5246 for ; Thu, 13 Feb 2020 07:57:55 -0600 (CST) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id 2G9Oj1Za0XVkQ2G9OjPXEP; Thu, 13 Feb 2020 09:11:34 -0600 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=embeddedor.com; s=default; h=Content-Type:MIME-Version:Message-ID:Subject: Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=mMH90DJQNFAtuTIHTFIPLDELcmZyic0yLac3lSYPFq4=; b=ImPLnHegN91Lx7ngWrKfqhpzwM GpMfnoN14gs1u80wKIVtfaA/jeQv7lADnlBF8y7jUea9GKNKngl8JDiIIlrsDQmfz6Dajx93S1jQ+ JvRHBDTYNR18wEhjyW+KXSZ7U3FdazimOJzej7h0UfscCusDgvKmWBaIxP2+xHWENo487X2KRoOSa thxtDPBixRefw07TnOFx72jxtxgK4Ikj2Q6XOn1tR7aJCPpUpUwmreQxMWzPVGLQBgmk5uQCnr+VZ XsGrPqxPPxGMoPca3YgEkHBdDIUIaokiOHcuA+M+5n95Duw28ZjJ7PSA8/Zv59xQ/p77BJ6Cq6rlK ZYBlRKAw==; Received: from [200.68.140.15] (port=28117 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.92) (envelope-from ) id 1j2G9M-0035UK-Ut; Thu, 13 Feb 2020 09:11:33 -0600 Date: Thu, 13 Feb 2020 09:14:09 -0600 From: "Gustavo A. R. Silva" To: Jessica Yu Cc: linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH] kernel: module: Replace zero-length array with flexible-array member Message-ID: <20200213151409.GA30541@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 200.68.140.15 X-Source-L: No X-Exim-ID: 1j2G9M-0035UK-Ut X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [200.68.140.15]:28117 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 2 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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