From patchwork Wed Apr 5 13:52:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 79614 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp333195vqo; Wed, 5 Apr 2023 07:06:43 -0700 (PDT) X-Google-Smtp-Source: AKy350avde6kQBAv9164HFoN3pzOHQUW6Y7t/uf0obgQltm249u+1R9z45g/gImE1G2E4L4T9Jgm X-Received: by 2002:aa7:c64c:0:b0:502:100c:53a with SMTP id z12-20020aa7c64c000000b00502100c053amr1990202edr.41.1680703602646; Wed, 05 Apr 2023 07:06:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680703602; cv=none; d=google.com; s=arc-20160816; b=QBpg9TXP+AaWTPuS+INYFUmq4sIZ1ZThagS1j5RQa2IWH4cOTEv402P33eLWVjIWu5 DJ/F8dTmnIB1+FUodNMZy0KFYGgh3QoE0aXnmzg11K5DclRcht2kqn+n5a1snKlOlhwY lr17Nn9QFAEc8KSRHFlvmfzy7zRpGMZ0EQQxFEKzkZe+YxmHtyZA991IpycP5r293RMI spKFpRNQPKdp3r44GZNmy9HZv0Cg6blASvYERH5jFmL0qkaUO+CcyuiRKXk7XDVRP4Dc l00q2B/fP0QRX8psekDhlNaJM03CkLbIr0xmHJu2PBSXrFEtSGPSs6RdSSNIqqHty3cL 8Ilg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=sbfRMAoUuLYYpb8z5zfyeisUSdGX3TAl7rxAgZEIEqU=; b=g7wwpkNxEXPxOx4BhbzyYtjo44NCTB7ttQkbWdEfxcmninnFb9kJ4xS8AO86RFz2BI h2VOuVjXIYxPetIggvEoWQsrrMv9wXAo4neEKj2ZKoErzEFRKd1T6bkjV7Aj6j2paAlD IbLK+SE2dGXIWBuQaM/PRNi+8gs3/8HKxL+bX8hlsF88hIT+PB2uviMU3YWP1we7l5mi ArIhPG2MY51tFQ0xeuPfBHt9kLnfRQ8dSz1Hbq3AhHIO9AWcqowhixJTYiDvVAunhsIL sTO+qXvdMD0ftjozqk15rN9a632wklAJe/xq1Tp+OrvsnDEgdeUOSSzYKwSMjGu0Z1nA xjng== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w12-20020a50fa8c000000b0050245e7f729si2669878edr.615.2023.04.05.07.06.17; Wed, 05 Apr 2023 07:06:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238265AbjDEOBP (ORCPT + 99 others); Wed, 5 Apr 2023 10:01:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238237AbjDEOA5 (ORCPT ); Wed, 5 Apr 2023 10:00:57 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76E40619F; Wed, 5 Apr 2023 07:00:51 -0700 (PDT) Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.1.0) id 7f235b38e99b158a; Wed, 5 Apr 2023 16:00:49 +0200 Received: from kreacher.localnet (unknown [213.134.163.219]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id 0635D1B4EA62; Wed, 5 Apr 2023 16:00:48 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Bob Moore , Kees Cook Subject: [PATCH 24/32] ACPICA: Introduce ACPI_FLEX_ARRAY Date: Wed, 05 Apr 2023 15:52:23 +0200 Message-ID: <9164448.rMLUfLXkoz@kreacher> In-Reply-To: <4845957.31r3eYUQgx@kreacher> References: <4845957.31r3eYUQgx@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 213.134.163.219 X-CLIENT-HOSTNAME: 213.134.163.219 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvhedrvdejuddgjeduucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepledtieekkeekveeikeetgffgteeuteefjeevjeegudelvdduheeiuedvieehieevnecuffhomhgrihhnpehgihhthhhusgdrtghomhenucfkphepvddufedrudefgedrudeifedrvdduleenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepihhnvghtpedvudefrddufeegrdduieefrddvudelpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeegpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprhhosggvrhhtrdhmohhorhgvsehinhhtvghlrdgtohhmpdhrtghpthhtohepkhgvvghssehouhht fhhluhigrdhnvght X-DCC--Metrics: v370.home.net.pl 1024; Body=4 Fuz1=4 Fuz2=4 X-Spam-Status: No, score=0.0 required=5.0 tests=SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762345460835765586?= X-GMAIL-MSGID: =?utf-8?q?1762345460835765586?= From: Kees Cook ACPICA commit e73b227e8e475c20cc394f237ea35d592fdf9ec3 In order to enable using -fstrict-flex-arrays with GCC and Clang in the Linux kernel, each trailing dynamically sized array must be defined as proper C99 "flexible array members" (FAM). Unfortunately, ACPICA has a bunch of technical debt, dating back to before even the GNU extension of 0-length arrays, meaning the code base has many 1-element and 0-length arrays defined at the end of structures that should actually be FAMs. One limitation of the C99 FAM specification is the accidental requirement that they cannot be in unions or alone in structs. There is no real-world reason for this, though, and, actually, the existing GNU extension permits this for 0-length arrays (which get treated as FAMs). Add the ACPI_FLEX_ARRAY() helper macro to work around this requirement so that FAMs can be defined in unions or alone in structs. Since this behavior still depends on GNU extensions, keep the macro specific to GCC (and Clang) builds. In this way, MSVC will continue to use 0-length arrays (since it does not support the union work-around). When MSVC grows support for this in the future, the macro can be updated. Link: https://github.com/acpica/acpica/commit/e73b227e Signed-off-by: Bob Moore Signed-off-by: Rafael J. Wysocki --- include/acpi/actypes.h | 4 ++++ include/acpi/platform/acgcc.h | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/acpi/actypes.h b/include/acpi/actypes.h index ce1db1c2e9d3..cf6ee2cb0eb9 100644 --- a/include/acpi/actypes.h +++ b/include/acpi/actypes.h @@ -1323,4 +1323,8 @@ typedef enum { #define ACPI_FALLTHROUGH do {} while(0) #endif +#ifndef ACPI_FLEX_ARRAY +#define ACPI_FLEX_ARRAY(TYPE, NAME) TYPE NAME[0] +#endif + #endif /* __ACTYPES_H__ */ diff --git a/include/acpi/platform/acgcc.h b/include/acpi/platform/acgcc.h index c9d418f9395e..04b4bf620517 100644 --- a/include/acpi/platform/acgcc.h +++ b/include/acpi/platform/acgcc.h @@ -61,4 +61,15 @@ #define ACPI_FALLTHROUGH __attribute__((__fallthrough__)) #endif +/* + * Flexible array members are not allowed to be part of a union under + * C99, but this is not for any technical reason. Work around the + * limitation. + */ +#define ACPI_FLEX_ARRAY(TYPE, NAME) \ + struct { \ + struct { } __Empty_ ## NAME; \ + TYPE NAME[]; \ + } + #endif /* __ACGCC_H__ */