From patchwork Sun May 28 20:26:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 99928 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1134859vqr; Sun, 28 May 2023 13:54:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7LxTsYMc5GdZ79qJ2oPShf4fUbK5g2CcmDSlmkdC1vwlEHnhR+F9rUxCm1OyaQWNUAuoFd X-Received: by 2002:a17:903:2291:b0:1b0:4883:2dff with SMTP id b17-20020a170903229100b001b048832dffmr93041plh.37.1685307287965; Sun, 28 May 2023 13:54:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685307287; cv=none; d=google.com; s=arc-20160816; b=r/+lXXISoycaTxJcIAzZyvyMeS6Q5gXhLk7k+koLl44FXpk1/EMfHKlWQUN13AXJDl V/4qrLWoLvSmy8NozdKvFE8MWYeQwr0CGn16vuGfYz7//s/HBm48ULv9XI3VzThcy3HT nTqwKLwJiL8JXsWb5WoyB+YRyWcYpBSYDioZT5t5JaHBebnKI3SDkMV4/ZnLWDhEoCYM 3lwJiFfJjMFiFirLPYCV+oYhuXOgJXwwnJHEhHxz8OBCcB5MkCIJpbvrtyTu+cDwlFOV pHTrxgFU0z8t6BBHYqUWng3+iSSNaPzy7t5npi/Tvn1VUibsl/Upi3jBnhZ49ODwJR9y lb2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=FA+icED9xpKNwqy6uLjfTyk2S4POOa2itWcoRMsZcTE=; b=lRjZBXhOVQ1+ifUZYOfPZ6L4+sEuXLwkR9gUx/HTMVeYDZbFcNMJmyrTNRYhNeI2rK QAx+0qG+0vrjxdIOWzv/7YJl/ut5fapIxl58wi/jYKclV+7N6HzdwQChQH50Ha5jqhM4 eqGspJL5uHgvrdhx+vNqiSDAjbMo6U+2s8jdGURKDebg770Y910pA+OS1Vb/X3Fo9rrn sS7IlSFzUOekL3gCnQ6c+hx+fbp0JuegGOrnCrwL4Z+WHeKZE8Gq3eKvR5UgTEeOc/L9 2vO7rizUs0on9agkwWGRd5tG3TG5wc+JuVjmy0HZNdrO42b6s3w3qpdASQdfvrRMjpj2 f/pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FTEYgj2F; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t13-20020a1709028c8d00b001aaf91ae3acsi7801336plo.485.2023.05.28.13.54.36; Sun, 28 May 2023 13:54:47 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FTEYgj2F; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229621AbjE1UZt (ORCPT + 99 others); Sun, 28 May 2023 16:25:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229584AbjE1UZs (ORCPT ); Sun, 28 May 2023 16:25:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDAC499; Sun, 28 May 2023 13:25:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6EE06618FF; Sun, 28 May 2023 20:25:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA952C433EF; Sun, 28 May 2023 20:25:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685305545; bh=e/BaBW7sBtQzZAFcqXZIr6cq7jQWmf347wE2UrNWXvo=; h=Date:From:To:Cc:Subject:From; b=FTEYgj2FnQEvAiguJAMacBw5p1NZqoD4NnK0xqagSVW2y+RV4Cy6CxnEkio28/hxW NJmTo1snvbRMzSKbItYqw/k5XlB7TtrylKaWr/Y/ZTHzrXpEeywm9kGGvVU/9VcRiW ula1LF2SKa1xNguOXil1199HZwd+escpztA2+cVA2hoo9oF7AbPGmubSYSH2JzWiCg ktVvceTgB9onw2zpkPvieEACFgIPInxQcMgUI92WJqYsOD+VP0GRwp7UD+O/EDsWb7 DsTGJHBPgtElBetm/i5rZsDZ1XjyaR9+jsJWglnF834kL83xR1IsQp8YqfbbAvbJB/ BKBPsvFTpMCeQ== Date: Sun, 28 May 2023 14:26:37 -0600 From: "Gustavo A. R. Silva" To: Alex Deucher , Christian =?iso-8859-1?q?K=F6n?= =?iso-8859-1?q?ig?= , "Pan, Xinhui" , David Airlie , Daniel Vetter Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] drm/amdgpu/discovery: Replace fake flex-arrays with flexible-array members Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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?1767172774656763265?= X-GMAIL-MSGID: =?utf-8?q?1767172774656763265?= Zero-length and one-element arrays are deprecated, and we are moving towards adopting C99 flexible-array members, instead. Use the DECLARE_FLEX_ARRAY() helper macro to transform zero-length arrays in a union into flexible-array members. And replace a one-element array with a C99 flexible-array member. Address the following warnings found with GCC-13 and -fstrict-flex-arrays=3 enabled: drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c:1009:89: warning: array subscript kk is outside array bounds of ‘uint32_t[0]’ {aka ‘unsigned int[]’} [-Warray-bounds=] drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c:1007:94: warning: array subscript kk is outside array bounds of ‘uint64_t[0]’ {aka ‘long long unsigned int[]’} [-Warray-bounds=] drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c:1310:94: warning: array subscript k is outside array bounds of ‘uint64_t[0]’ {aka ‘long long unsigned int[]’} [-Warray-bounds=] drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c:1309:57: warning: array subscript k is outside array bounds of ‘uint32_t[0]’ {aka ‘unsigned int[]’} [-Warray-bounds=] This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy() and help us make progress towards globally enabling -fstrict-flex-arrays=3 [1]. This results in no differences in binary output. Link: https://github.com/KSPP/linux/issues/21 Link: https://github.com/KSPP/linux/issues/193 Link: https://github.com/KSPP/linux/issues/300 Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1] Signed-off-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- drivers/gpu/drm/amd/include/discovery.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/amd/include/discovery.h b/drivers/gpu/drm/amd/include/discovery.h index 9181e57887db..f43e29722ef7 100644 --- a/drivers/gpu/drm/amd/include/discovery.h +++ b/drivers/gpu/drm/amd/include/discovery.h @@ -122,7 +122,7 @@ typedef struct ip_v3 uint8_t sub_revision : 4; /* HCID Sub-Revision */ uint8_t variant : 4; /* HW variant */ #endif - uint32_t base_address[1]; /* Base Address list. Corresponds to the num_base_address field*/ + uint32_t base_address[]; /* Base Address list. Corresponds to the num_base_address field*/ } ip_v3; typedef struct ip_v4 { @@ -140,8 +140,8 @@ typedef struct ip_v4 { uint8_t sub_revision : 4; /* HCID Sub-Revision */ #endif union { - uint32_t base_address[0]; /* 32-bit Base Address list. Corresponds to the num_base_address field*/ - uint64_t base_address_64[0]; /* 64-bit Base Address list. Corresponds to the num_base_address field*/ + DECLARE_FLEX_ARRAY(uint32_t, base_address); /* 32-bit Base Address list. Corresponds to the num_base_address field*/ + DECLARE_FLEX_ARRAY(uint64_t, base_address_64); /* 64-bit Base Address list. Corresponds to the num_base_address field*/ } __packed; } ip_v4;