From patchwork Wed Nov 9 07:33:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paulo Miguel Almeida X-Patchwork-Id: 17372 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp198481wru; Tue, 8 Nov 2022 23:36:03 -0800 (PST) X-Google-Smtp-Source: AMsMyM6xkaqz3NOjI9FUIazU0Tx/ZWaqmSsGquaOch/vuuWe3COd/LqSP6DrzfwVW3d8WaXIzRz0 X-Received: by 2002:a63:595:0:b0:470:8b7:255a with SMTP id 143-20020a630595000000b0047008b7255amr32232331pgf.329.1667979362844; Tue, 08 Nov 2022 23:36:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667979362; cv=none; d=google.com; s=arc-20160816; b=al7SJeHZzqbXlE40PtdBS5zKve+KQ6MMfV8VRDDhU0jH9C3uu0qKb6VudSufX9Bhjy ylYTipYLjEkYiQ5BbTwt1twKKBGBFI2ivVxqWtx6eDSzJV8+sb8wdXg/b88bNnv6dew7 Tw/0eJCw+Lwqwj9/LMPqNDMgsWl43irfe9FTaCFQi3MNvPwMuk9PCcMSy3GgmVF3xDRt rxv9ilK2iov7a7Teps6qB4BNg9ryqmVz9p7k6vn6dsZbj/zWrB67rXzdWE77LHT3Nsxg e0sWPkl716V5XvC9W/jy0My/yD7SH0z+cWI0Zp5uXB4zPvzaByrT4ZlndHD8HmkUjeps YL4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=VfaZWHmp3/7/i2FUcNx0O07NB6LAM0d+BKVvnY3XIXQ=; b=Wq/IenkEE/2teRZi5J+2xQWJ7Yhk4khnnv70F47SfTOSR0gF690BMOi0b2rk+O+kQK FwpJ2HOgane0q2M2Q6swHBvYdSzOF4N6ZQ5wGM05jGLBice2eTHzWh2GDYfDuxIcD2yl 5Xd7YrGEJS5dKVPs/CR+m4jVqc7pDM8pURIecXGOGJSUYSoKkgN7fqxZFiEBsJC2DH7s cD1mgGBGYRJQhh9ItvhrkkYnT980N1nitTELpu+LWl4HFzRQNEYuJH/Bny+Dxrsxr73n h8WwsMdds1JoPReW4iuc0bPJIM0vma4kDexsCCUMbCQF97zL99kz1GyytMrqPC3cM1JI VPyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OxH7ylJe; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y22-20020a656c16000000b00434c2c0a834si16500493pgu.734.2022.11.08.23.35.49; Tue, 08 Nov 2022 23:36:02 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=OxH7ylJe; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229615AbiKIHdq (ORCPT + 99 others); Wed, 9 Nov 2022 02:33:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbiKIHdp (ORCPT ); Wed, 9 Nov 2022 02:33:45 -0500 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1156D13D30; Tue, 8 Nov 2022 23:33:44 -0800 (PST) Received: by mail-pl1-x62c.google.com with SMTP id d20so15266075plr.10; Tue, 08 Nov 2022 23:33:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=VfaZWHmp3/7/i2FUcNx0O07NB6LAM0d+BKVvnY3XIXQ=; b=OxH7ylJeFIRsKDTt8VIrBbStjYgYgrC93Tuq1Ce85J8FaMUb331253zbKb/d+gz2CV S3BHwSUR9VEt/01g5dj7YZvuAZyPadh8mQRXt6IM8M0FB4G2uVQ7qoZw3iH3XWAnOMWk DR5iA9VuGZC1f56rYHWLX6xWDjZq0/JK2LIs+FCPyYGkK/OtTq0nYFxiKJfEiKvunL/J +0W5RS7MzpoxZFXoRFjpBhZNk9anROYWmyI1+3e6wg9wijWiEJQoTE9A95pVtTFzp2Qb wsG00051zMCpPfTU8PyVl8OwPpk4vd7I2d4Y8Pp33cQjQTNVa7kNQhySRgzRzq6w6Vhr mlcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VfaZWHmp3/7/i2FUcNx0O07NB6LAM0d+BKVvnY3XIXQ=; b=PWExWd0RXUQpm6kJyFpIMKBjQCmpJ6hCIjmPlvcTaZO86hdH7Vf0oO1M4GS+0mIEEc 9dEvaZKgq3mUMDOYXtoHv/qVmEYc6tkPVOWoN94uvYy2DFhJ8zsTDzdZ+ts5zZ5GFKSZ +8dHEdNYiFpR5brJxUhkVBNjwAW00HkVc2x47LdGiQTJbrzNUnkYruk+BBs/1gq+jjUm F7EqB8F8nV0RPob16WH/T3kEgDSpvLtK4xZZCK1HN/IAQqR21eIi9SlJ4k8tt9LzJQ0f f2kvXd7ybHh9VZUQyW5X8wrV6uvfrP1Pc3GqgUYX5wUrJ3OUG8/7lQIkWMtYB77ULAne MUxg== X-Gm-Message-State: ACrzQf2f5s69vZv1IdYm0P4VHQsN1DVawUt8eShFeIeQ/fdMQ/aA3j0j gcbyJRpxO7lMtrQdxtH1gJU= X-Received: by 2002:a17:90b:19d1:b0:213:7030:6bd9 with SMTP id nm17-20020a17090b19d100b0021370306bd9mr61643441pjb.43.1667979223474; Tue, 08 Nov 2022 23:33:43 -0800 (PST) Received: from mail.google.com (125-237-50-34-fibre.sparkbb.co.nz. [125.237.50.34]) by smtp.gmail.com with ESMTPSA id h14-20020a056a00000e00b0056bc9294e1asm7579920pfk.24.2022.11.08.23.33.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 23:33:43 -0800 (PST) Date: Wed, 9 Nov 2022 20:33:34 +1300 From: Paulo Miguel Almeida To: Harry Wentland , Leo Li , Rodrigo Siqueira , Alex Deucher , Christian =?utf-8?b?S8O2bmln?= , "Pan, Xinhui" , David Airlie , Daniel Vetter , Paulo Miguel Almeida , Rongguang Wei , Slark Xiao , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, paulo.miguel.almeida.rodenas@gmail.com Subject: [PATCH] [next] drm/amdgpu: Replace one-element array with flex-array member Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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?1749003128378575678?= X-GMAIL-MSGID: =?utf-8?q?1749003128378575678?= One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace one-element array with flexible-array member in structs _ATOM_CONNECTOR_DEVICE_TAG_RECORD, _ATOM_OBJECT_GPIO_CNTL_RECORD, _ATOM_BRACKET_LAYOUT_RECORD, _ATOM_BRACKET_LAYOUT_RECORD, _ATOM_LEAKAGE_VOLTAGE_OBJECT_V3, _ATOM_FUSION_SYSTEM_INFO_V3, _ATOM_I2C_DATA_RECORD, _ATOM_I2C_DEVICE_SETUP_INFO, _ATOM_ASIC_MVDD_INFO and refactor the rest of the code accordingly. While at it, removed a redundant casting. Important to mention is that doing a build before/after this patch results in no binary output differences. 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]. Link: https://github.com/KSPP/linux/issues/79 Link: https://github.com/KSPP/linux/issues/238 Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101836 [1] Signed-off-by: Paulo Miguel Almeida --- Alex, I noticed a few structs in atombios.h that were not referenced. Is there any appetite for removing them? Or is that one of those cases where the structs are there should one driver ever need it? Ex.: struct _ATOM_I2C_DATA_RECORD struct _ATOM_I2C_DEVICE_SETUP_INFO struct _ATOM_ASIC_MVDD_INFO --- .../gpu/drm/amd/display/dc/bios/bios_parser.c | 5 ++--- drivers/gpu/drm/amd/include/atombios.h | 16 ++++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/amd/display/dc/bios/bios_parser.c b/drivers/gpu/drm/amd/display/dc/bios/bios_parser.c index 39dd8b2dc254..6b9e64cd4379 100644 --- a/drivers/gpu/drm/amd/display/dc/bios/bios_parser.c +++ b/drivers/gpu/drm/amd/display/dc/bios/bios_parser.c @@ -2606,8 +2606,7 @@ static enum bp_result update_slot_layout_info( for (;;) { - record_header = (ATOM_COMMON_RECORD_HEADER *) - GET_IMAGE(ATOM_COMMON_RECORD_HEADER, record_offset); + record_header = GET_IMAGE(ATOM_COMMON_RECORD_HEADER, record_offset); if (record_header == NULL) { result = BP_RESULT_BADBIOSTABLE; break; @@ -2621,7 +2620,7 @@ static enum bp_result update_slot_layout_info( if (record_header->ucRecordType == ATOM_BRACKET_LAYOUT_RECORD_TYPE && - sizeof(ATOM_BRACKET_LAYOUT_RECORD) + struct_size(record, asConnInfo, 1) <= record_header->ucRecordSize) { record = (ATOM_BRACKET_LAYOUT_RECORD *) (record_header); diff --git a/drivers/gpu/drm/amd/include/atombios.h b/drivers/gpu/drm/amd/include/atombios.h index 55ae93c1e365..60c44a8a067f 100644 --- a/drivers/gpu/drm/amd/include/atombios.h +++ b/drivers/gpu/drm/amd/include/atombios.h @@ -4733,7 +4733,7 @@ typedef struct _ATOM_CONNECTOR_DEVICE_TAG_RECORD ATOM_COMMON_RECORD_HEADER sheader; UCHAR ucNumberOfDevice; UCHAR ucReserved; - ATOM_CONNECTOR_DEVICE_TAG asDeviceTag[1]; //This Id is same as "ATOM_DEVICE_XXX_SUPPORT", 1 is only for allocation + ATOM_CONNECTOR_DEVICE_TAG asDeviceTag[]; //This Id is same as "ATOM_DEVICE_XXX_SUPPORT" }ATOM_CONNECTOR_DEVICE_TAG_RECORD; @@ -4793,7 +4793,7 @@ typedef struct _ATOM_OBJECT_GPIO_CNTL_RECORD ATOM_COMMON_RECORD_HEADER sheader; UCHAR ucFlags; // Future expnadibility UCHAR ucNumberOfPins; // Number of GPIO pins used to control the object - ATOM_GPIO_PIN_CONTROL_PAIR asGpio[1]; // the real gpio pin pair determined by number of pins ucNumberOfPins + ATOM_GPIO_PIN_CONTROL_PAIR asGpio[]; // the real gpio pin pair determined by number of pins ucNumberOfPins }ATOM_OBJECT_GPIO_CNTL_RECORD; //Definitions for GPIO pin state @@ -4982,7 +4982,7 @@ typedef struct _ATOM_BRACKET_LAYOUT_RECORD UCHAR ucWidth; UCHAR ucConnNum; UCHAR ucReserved; - ATOM_CONNECTOR_LAYOUT_INFO asConnInfo[1]; + ATOM_CONNECTOR_LAYOUT_INFO asConnInfo[]; }ATOM_BRACKET_LAYOUT_RECORD; @@ -5161,7 +5161,7 @@ typedef struct _ATOM_GPIO_VOLTAGE_OBJECT_V3 UCHAR ucPhaseDelay; // phase delay in unit of micro second UCHAR ucReserved; ULONG ulGpioMaskVal; // GPIO Mask value - VOLTAGE_LUT_ENTRY_V2 asVolGpioLut[1]; + VOLTAGE_LUT_ENTRY_V2 asVolGpioLut[]; }ATOM_GPIO_VOLTAGE_OBJECT_V3; typedef struct _ATOM_LEAKAGE_VOLTAGE_OBJECT_V3 @@ -5171,7 +5171,7 @@ typedef struct _ATOM_LEAKAGE_VOLTAGE_OBJECT_V3 UCHAR ucLeakageEntryNum; // indicate the entry number of LeakageId/Voltage Lut table UCHAR ucReserved[2]; ULONG ulMaxVoltageLevel; - LEAKAGE_VOLTAGE_LUT_ENTRY_V2 asLeakageIdLut[1]; + LEAKAGE_VOLTAGE_LUT_ENTRY_V2 asLeakageIdLut[]; }ATOM_LEAKAGE_VOLTAGE_OBJECT_V3; @@ -6599,7 +6599,7 @@ typedef struct _ATOM_FUSION_SYSTEM_INFO_V3 typedef struct _ATOM_I2C_DATA_RECORD { UCHAR ucNunberOfBytes; //Indicates how many bytes SW needs to write to the external ASIC for one block, besides to "Start" and "Stop" - UCHAR ucI2CData[1]; //I2C data in bytes, should be less than 16 bytes usually + UCHAR ucI2CData[]; //I2C data in bytes, should be less than 16 bytes usually }ATOM_I2C_DATA_RECORD; @@ -6610,14 +6610,14 @@ typedef struct _ATOM_I2C_DEVICE_SETUP_INFO UCHAR ucSSChipID; //SS chip being used UCHAR ucSSChipSlaveAddr; //Slave Address to set up this SS chip UCHAR ucNumOfI2CDataRecords; //number of data block - ATOM_I2C_DATA_RECORD asI2CData[1]; + ATOM_I2C_DATA_RECORD asI2CData[]; }ATOM_I2C_DEVICE_SETUP_INFO; //========================================================================================== typedef struct _ATOM_ASIC_MVDD_INFO { ATOM_COMMON_TABLE_HEADER sHeader; - ATOM_I2C_DEVICE_SETUP_INFO asI2CSetup[1]; + ATOM_I2C_DEVICE_SETUP_INFO asI2CSetup[]; }ATOM_ASIC_MVDD_INFO; //==========================================================================================