Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp300413ybf; Wed, 26 Feb 2020 13:25:22 -0800 (PST) X-Google-Smtp-Source: APXvYqw/t5eY7y5YOQ3Y+TkpWL5szTVxHkPi6gDNveI690aAdcCOxIKevcUSh0k6/uFdmff45S5H X-Received: by 2002:a9d:6e8f:: with SMTP id a15mr659185otr.178.1582752322383; Wed, 26 Feb 2020 13:25:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582752322; cv=none; d=google.com; s=arc-20160816; b=maqcnnX6KQoGQC/aDYHbxuvDEZqzLNynSNy4agbS5pneDs/ljFCHdXIFsxodxV3/+U nxipXPO+26G2jvJjvkV1FglRUSv1VvNElu4CJsHBZcVZ8lZmKuxdb8iFQpnwqlj+jlUz AD92CyPkD1HlYEKWXQdrdSoNmvC+yxRMuTTOY1uIJB2GoHmatrqkK+VwVr3dKSlyLw80 4tCn1khPOkuh5KFL9HlxGFdhgVePAq4CodrGhBx8I0TABxDmL38tIkw/izQOq4yBAwXl rSc0v7o/kQYJGLDFxiQ1YaTxvPFOXVuyD+3r5kqhwoxMtnnpKf86axQZtqHp+JRY4IKl 2p/A== 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=96f8kZdh7WxJBTeep/qoxEO5hEENwT7hPTi1FGgDDyQ=; b=BqS1Bg60L6fh56RT33g6i9/7QvelcufvQdw5wX2E5Gv6h31wIr3wUebbWz5H/83tCT 5nxQXdXkcNQRxMaT2tao6po5j4YiDTdzILtJUMegFMBzK53H09i7Ufnb1CH/qkuSpqX5 L3BwPWmV6KIlEL/wvmTVaKUP438qS3lZTGfZtqZ4aJYBkWChv6z6o4PY+5sK61z1eTwU /dASsGvPAF5ji0vEEoaDS/7x13sBva70Z5+xiqgZp7CI8cxr9cKpQVkpp4T9ghtn2FdG e1Zbs6FDa85P1Wkpn2FAnZHGYU8yEI1Pi0dKnIbGXp3gETdu391zGCNVMc6h5Euiaenx 1ENQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b=BZl1WCjg; 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 j20si241374oii.80.2020.02.26.13.25.08; Wed, 26 Feb 2020 13:25:22 -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=BZl1WCjg; 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 S1727591AbgBZVXd (ORCPT + 99 others); Wed, 26 Feb 2020 16:23:33 -0500 Received: from gateway24.websitewelcome.com ([192.185.51.202]:46198 "EHLO gateway24.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727503AbgBZVXd (ORCPT ); Wed, 26 Feb 2020 16:23:33 -0500 Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway24.websitewelcome.com (Postfix) with ESMTP id 7E02954B5A for ; Wed, 26 Feb 2020 15:23:31 -0600 (CST) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id 749TjFxwYXVkQ749TjbBCH; Wed, 26 Feb 2020 15:23:31 -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=96f8kZdh7WxJBTeep/qoxEO5hEENwT7hPTi1FGgDDyQ=; b=BZl1WCjgZtTNu6aGLvvU4/iPRW KLaA1o7tDonP3BUGMMHpFTH76EWmdNlvIEgVkNuMfKiiZDRQe7i00Bf5C2djTnOF+TcPoYjgNKncA Rlqx5Ed5Ra7TtDi9045eAvLfhpfmdWkr6BdOj1U1j6rxT+1kY/qpWzi2R72Qh49C2R7mauhdDHCTG snYO5LP6796MkyQirOLPQ+m483LtTmhx20oZlAze2cojPgR01142altotg30XfkciRi+LRxCckTCd HPHeyB5uYVzEWI5qUaAsA2gTE8sOZ2IFKcI4zv9NnCa5B7N0FTXEmmOKZlauQzSKfqO/Ro6LjxnZ8 gzd3TRow==; Received: from [201.162.161.180] (port=47722 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.92) (envelope-from ) id 1j749R-000nRw-Iy; Wed, 26 Feb 2020 15:23:30 -0600 Date: Wed, 26 Feb 2020 15:26:12 -0600 From: "Gustavo A. R. Silva" To: Boris Ostrovsky , Juergen Gross , Stefano Stabellini Cc: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH] xen: Replace zero-length array with flexible-array member Message-ID: <20200226212612.GA4663@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: 201.162.161.180 X-Source-L: No X-Exim-ID: 1j749R-000nRw-Iy X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [201.162.161.180]:47722 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 21 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 --- drivers/xen/xen-pciback/pciback.h | 2 +- include/xen/interface/io/tpmif.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/xen/xen-pciback/pciback.h b/drivers/xen/xen-pciback/pciback.h index ce1077e32466..7c95516a860f 100644 --- a/drivers/xen/xen-pciback/pciback.h +++ b/drivers/xen/xen-pciback/pciback.h @@ -52,7 +52,7 @@ struct xen_pcibk_dev_data { unsigned int ack_intr:1; /* .. and ACK-ing */ unsigned long handled; unsigned int irq; /* Saved in case device transitions to MSI/MSI-X */ - char irq_name[0]; /* xen-pcibk[000:04:00.0] */ + char irq_name[]; /* xen-pcibk[000:04:00.0] */ }; /* Used by XenBus and xen_pcibk_ops.c */ diff --git a/include/xen/interface/io/tpmif.h b/include/xen/interface/io/tpmif.h index 28e7dcd75e82..f8aa8bac5196 100644 --- a/include/xen/interface/io/tpmif.h +++ b/include/xen/interface/io/tpmif.h @@ -46,7 +46,7 @@ struct vtpm_shared_page { uint8_t pad; uint8_t nr_extra_pages; /* extra pages for long packets; may be zero */ - uint32_t extra_pages[0]; /* grant IDs; length in nr_extra_pages */ + uint32_t extra_pages[]; /* grant IDs; length in nr_extra_pages */ }; #endif -- 2.25.0