From patchwork Mon Jan 8 11:48:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Richter X-Patchwork-Id: 13513327 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A54722EF1; Mon, 8 Jan 2024 11:49:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="aUgv7FUE" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WxYdpRT0BUXPY5Xr7UhskROxwJE5+leVYEM92JZd7zUF8Bb4ue1B0PDtGtsyrrwjtY5coVV4Xt6cKeOHmWNK9EEVwQPPlGyz6N0eg7nwiFu7cTJpVRuFrtQRN/6hxgOg/chrnicISxaKEwkO1Zl1lq2/pPFKmly9DzY5w3eAIJvdeNyQ962fwOSe/wDh+B8dzAWx9650xmbHeumvx2wzrirGZB6KHD1Dxv+lKd2b2PmSnH5Sel7lBXRrS9W/VxMyvgFhvM6NoN0dra4rgZQCoSfzFF61qV+m2nR4ZhpSF/fGSYWbV0DmrfB5iAdKuww7rgeAZ8x8gelvHWm/LKU4aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=q9GJUTx4FVwx/+DkcJ4CAYVAFGXTw4AsaHw//qzGr0M=; b=SqEPrOUeSKRYBQyOr8FoCPmrINIDiheJbe+mX5po4te+Q5YTdHXdqcdvyhGI3DAKGZESiLBWkQvroovytq/LaO7gAcZnksWgVdJ+0iAaVebbmMiycKq9oGbiYXnd6N4TdUXoq9Gwk34tBwn1n4WpyMuXb9qOWQC3jRs9dduROqsn9QHs8j0oCbOrnYGIg2hbIkyrmEekJ1KNoX4zhkS4sbGSzTLVPmValiJHmMSIttj5cpwbLJsDW/SSlLV4Lx5UfBena/Wuzzmm67HPRbf0B/FmowE7m61lBd5tb4a2t2r7tHuUhm3FtEY/RzcgolD3XCNZxiFJyle8GeYCdbW77A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=q9GJUTx4FVwx/+DkcJ4CAYVAFGXTw4AsaHw//qzGr0M=; b=aUgv7FUEvccwIJLZOwXmB93Lug4m68QCnUh+bCuJk2lzz6jIWwdgYpgFr0C33FOko0R7dl2LHd6t4Uhll2k2vVAm4yRRmtYpJmwDib6MV53sGLCVwBW0MSopIiz4bRBic6OuLOZmIVQrs6Les7vKnHjZbQR8n5SDSkcVo26SJp0= Received: from PR0P264CA0086.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:18::26) by CH2PR12MB4149.namprd12.prod.outlook.com (2603:10b6:610:7c::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.23; Mon, 8 Jan 2024 11:49:14 +0000 Received: from SA2PEPF000015CA.namprd03.prod.outlook.com (2603:10a6:100:18:cafe::62) by PR0P264CA0086.outlook.office365.com (2603:10a6:100:18::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.21 via Frontend Transport; Mon, 8 Jan 2024 11:49:14 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SA2PEPF000015CA.mail.protection.outlook.com (10.167.241.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7181.13 via Frontend Transport; Mon, 8 Jan 2024 11:49:13 +0000 Received: from rric.localdomain (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Mon, 8 Jan 2024 05:49:10 -0600 From: Robert Richter To: Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Jonathan Cameron , Dave Jiang , Davidlohr Bueso CC: , , "Rafael J. Wysocki" , Len Brown , Robert Richter Subject: [PATCH v2 1/3] cxl/pci: Rename DOE mailbox handle to doe_mb Date: Mon, 8 Jan 2024 12:48:31 +0100 Message-ID: <20240108114833.241710-2-rrichter@amd.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240108114833.241710-1-rrichter@amd.com> References: <20240108114833.241710-1-rrichter@amd.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF000015CA:EE_|CH2PR12MB4149:EE_ X-MS-Office365-Filtering-Correlation-Id: c0640794-43b2-4e22-e657-08dc103fd5ec X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FwIcroLWKO01xnsbCHlY9VUDxR7RU55qfSN0edlToGUg0TtxUw50EnT9pF5yAKweZYG2Gj315dtQanJv5CsfIW4z+HbZXzv7KHWT2CYH6zrpSTDip2upTtGfTerrShxp5fyRUY4/789S1vMN0hs6jFhe4MXpseXJ1QdvtPlkhM1RPRnUdZBVCvzixkUpIJuFembWVaO9TiLT35lyF7vT3LOy8xIRi6I3bQQXvkfni+RcpKjxKAep82GHCZm/2Y0VV2HJKL/AVCNT3TVgvwi3RrV7g5SoebfwrwzvpGE/RUpEtaf2poAtGAXKZ/knk+UB5Hsj89ThfaAAAQfC/CAElm9f01fhgPU8CY+WtmJZBoxNKv772Q1vZLTktX8pc/wciqgGXwQwGJZ+xStSF5PkYAOrJpzKrY6qJmHPaauvNvnil0keXkiM0AnEVlZBZmGNtFZI0xUkP+FI6xvrsAnOK4lccT0Quono1aGe/1orNzAx51JZySkUTuvLmUXYZ3PETqzac3P0/Stoq/UCB9GWvBDsCbOalZDtdjlzetzL5zoC0nBrjBdJV1j3vNoD7t31dt246F6oLGt+qqMkLBo1g9BZy7zyZKAEoyLDvoHWDEiJYVXz/TY+R++2YKfzOM4N/TxYM5nXWvnUvKWtuzjixgpr7dAl7TCPyra1CfMbEPutmNQc6Btp9dwKfC3kIi8/vHGdaGPPfCg4LQtE+bSwodnzDbFnwrH/xpnUwIf7hEU+VQKvvnVQ3L3Galk01qbacnCeutNIHxXJ2zsB8tWywg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(396003)(136003)(376002)(346002)(39860400002)(230922051799003)(451199024)(64100799003)(1800799012)(186009)(82310400011)(40470700004)(36840700001)(46966006)(2906002)(7416002)(15650500001)(5660300002)(82740400003)(81166007)(41300700001)(356005)(336012)(16526019)(36860700001)(316002)(54906003)(110136005)(426003)(36756003)(8676002)(47076005)(8936002)(2616005)(40460700003)(70206006)(70586007)(40480700001)(26005)(1076003)(478600001)(83380400001)(6666004)(4326008)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jan 2024 11:49:13.7355 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c0640794-43b2-4e22-e657-08dc103fd5ec X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF000015CA.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4149 Trivial variable rename for the DOE mailbox handle from cdat_doe to doe_mb. The variable name cdat_doe is too ambiguous, use doe_mb that is commonly used for the mailbox. Signed-off-by: Robert Richter Reviewed-by: Dave Jiang Reviewed-by: Jonathan Cameron --- drivers/cxl/core/pci.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c index 6c9c8d92f8f7..89bab00bb291 100644 --- a/drivers/cxl/core/pci.c +++ b/drivers/cxl/core/pci.c @@ -518,14 +518,14 @@ EXPORT_SYMBOL_NS_GPL(cxl_hdm_decode_init, CXL); FIELD_PREP(CXL_DOE_TABLE_ACCESS_ENTRY_HANDLE, (entry_handle))) static int cxl_cdat_get_length(struct device *dev, - struct pci_doe_mb *cdat_doe, + struct pci_doe_mb *doe_mb, size_t *length) { __le32 request = CDAT_DOE_REQ(0); __le32 response[2]; int rc; - rc = pci_doe(cdat_doe, PCI_DVSEC_VENDOR_ID_CXL, + rc = pci_doe(doe_mb, PCI_DVSEC_VENDOR_ID_CXL, CXL_DOE_PROTOCOL_TABLE_ACCESS, &request, sizeof(request), &response, sizeof(response)); @@ -543,7 +543,7 @@ static int cxl_cdat_get_length(struct device *dev, } static int cxl_cdat_read_table(struct device *dev, - struct pci_doe_mb *cdat_doe, + struct pci_doe_mb *doe_mb, void *cdat_table, size_t *cdat_length) { size_t length = *cdat_length + sizeof(__le32); @@ -557,7 +557,7 @@ static int cxl_cdat_read_table(struct device *dev, size_t entry_dw; int rc; - rc = pci_doe(cdat_doe, PCI_DVSEC_VENDOR_ID_CXL, + rc = pci_doe(doe_mb, PCI_DVSEC_VENDOR_ID_CXL, CXL_DOE_PROTOCOL_TABLE_ACCESS, &request, sizeof(request), data, length); @@ -617,7 +617,7 @@ void read_cdat_data(struct cxl_port *port) { struct device *uport = port->uport_dev; struct device *dev = &port->dev; - struct pci_doe_mb *cdat_doe; + struct pci_doe_mb *doe_mb; struct pci_dev *pdev = NULL; struct cxl_memdev *cxlmd; size_t cdat_length; @@ -638,16 +638,16 @@ void read_cdat_data(struct cxl_port *port) if (!pdev) return; - cdat_doe = pci_find_doe_mailbox(pdev, PCI_DVSEC_VENDOR_ID_CXL, - CXL_DOE_PROTOCOL_TABLE_ACCESS); - if (!cdat_doe) { + doe_mb = pci_find_doe_mailbox(pdev, PCI_DVSEC_VENDOR_ID_CXL, + CXL_DOE_PROTOCOL_TABLE_ACCESS); + if (!doe_mb) { dev_dbg(dev, "No CDAT mailbox\n"); return; } port->cdat_available = true; - if (cxl_cdat_get_length(dev, cdat_doe, &cdat_length)) { + if (cxl_cdat_get_length(dev, doe_mb, &cdat_length)) { dev_dbg(dev, "No CDAT length\n"); return; } @@ -656,7 +656,7 @@ void read_cdat_data(struct cxl_port *port) if (!cdat_buf) return; - rc = cxl_cdat_read_table(dev, cdat_doe, cdat_buf, &cdat_length); + rc = cxl_cdat_read_table(dev, doe_mb, cdat_buf, &cdat_length); if (rc) goto err; From patchwork Mon Jan 8 11:48:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Richter X-Patchwork-Id: 13513328 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE2FC28E25; Mon, 8 Jan 2024 11:49:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="xj6wrCd8" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JiBlSrrOFuYrESjzTqgJWL4N1aeWQktzKxuOaRRj1C7cppJR/G4vab26tE9qUMqJ9kYLCJBrmLA1m179g5LziPu94sWQm+uZkyzkbsLWX8UZ0IJc3/ofdG97/pJi7sDfRK7GgBI5r6RXjV1mdYPP7jkd0N4yoYGrSBiVMaS8mxp2AwbA5jFVjpxPrC8Ei9MgwooU6XGtPl0NXQXXsuBxvB7Bi4YYgQHYu96WLvGqwlrDnr3c+weYk2NUh+HKhYkA9wBanFDtIBuU5J6f8Q8HKkJW9QQCalVuoda5QNKzBX4LuvI/xhqEJbPlPimGdDE6RX+slTZYF1XLQ11qTTtvHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pvbJ71b9pImc8Q7qiX3rlBKTfITFZmtuDok4Y6axR6g=; b=iV8HNHxhoc8MvM6obWTtDlytb/2sx8562XwTa9YI0LKmpbiglkhflcY9Pn78o1dgG9UzTOjN3qMaaPaszrbNim5ntpmh9u5G7fV6SBFIGw/sHrDgy/c1SM+MLCgviN5OzlWvTyA6YXYtWlKA3iY7f1zOHCdpNKEUh/wYqHUUmPOcwxLEt8CIPTTJl5/uDrGaN3Sq5kism1Bpaa5J/5hsaa+ab6WaIqo+uMxV0cu+KiXOAjaYfs7/urcDRV0FUuiObHeznGGg/kWaI40XiWGo7UDJ6O4Bu8E7lkP83ei5OQlU9FkHwjWOKvGjeUi1MSoLQMsMWauyeJD9RCeRC/eihg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pvbJ71b9pImc8Q7qiX3rlBKTfITFZmtuDok4Y6axR6g=; b=xj6wrCd8RMVpCLbtWHlzEeeb9dz0PW3keFjd388P/SuknUnkIodV1bBAAZIrJET3dZbrRVLaghAjLnrxXJWXyLOHkbb08s3qMve+krMT3/ToeasEw6OPEIY54DkEmQyte9EA2K5sGTyiJI53cQeOMjk0PsC+ZGKtvZDLM2IDzKA= Received: from PR0P264CA0094.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:18::34) by DS0PR12MB9346.namprd12.prod.outlook.com (2603:10b6:8:1be::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.21; Mon, 8 Jan 2024 11:49:19 +0000 Received: from SA2PEPF000015CA.namprd03.prod.outlook.com (2603:10a6:100:18:cafe::eb) by PR0P264CA0094.outlook.office365.com (2603:10a6:100:18::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.21 via Frontend Transport; Mon, 8 Jan 2024 11:49:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SA2PEPF000015CA.mail.protection.outlook.com (10.167.241.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7181.13 via Frontend Transport; Mon, 8 Jan 2024 11:49:17 +0000 Received: from rric.localdomain (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Mon, 8 Jan 2024 05:49:14 -0600 From: Robert Richter To: Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Jonathan Cameron , Dave Jiang , Davidlohr Bueso CC: , , "Rafael J. Wysocki" , Len Brown , Robert Richter , Lukas Wunner , Fan Ni Subject: [PATCH v2 2/3] cxl/pci: Get rid of pointer arithmetic reading CDAT table Date: Mon, 8 Jan 2024 12:48:32 +0100 Message-ID: <20240108114833.241710-3-rrichter@amd.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240108114833.241710-1-rrichter@amd.com> References: <20240108114833.241710-1-rrichter@amd.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF000015CA:EE_|DS0PR12MB9346:EE_ X-MS-Office365-Filtering-Correlation-Id: 077a0f8a-2958-45a4-f464-08dc103fd821 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ENrKDDTE72upM/kQ6x41H+PB7rJnSO3p0MObSmH4eDGyfqadAHkKS/AS7gd5zoJof0OsSJoIJl5xbOox53PjWyge1NMUDMQzRdcgd/2vWCEMwPU39kQdjB2oVgpV1Sq9ALY5bCz4yIFwyqoc3LWtVk6fTU4/fmqoKHwbfOtCPGGXkw+XSnYNw32ne2X57ya8TRhcoFnL7U2+kW+zNtWLW4xPtI46gJQvoPwOVm19bXimjhhsxx3eIJFep3/4pPdVjw/s8mEfmEiEuF8kJc1tl9BB2WY59ZR83odJunFC/jYWUS3Z1+6Vr8Q1bu6yYcSQIKILVzfxv/Ebppw2WC7JIxHDc9pIduBtFVXAp7oIWSMyaRQlFavD//E3V+L5oS0gsy9iaEgqzpk7VMAOxoBAI630OXlhVUHtyYhz2QqwhL3HoK5bQ5yYdqt8nQ8jp15VC1oXPc8bBorzDvW+/tqg1+4oTlM7XpG6wAbxgVme0+xZ1GpoUoTdj7PPz8arqzIlkSElz8XvGHPYZHdTumhi9Z9+1L9UrYOWrnRhp7etnIy89p39DsTS6gdXxkhcTo3PuUmYFIdqcEZJrwcwBRRgGjaWDAvY+QJlouqeUH11IiId+BYY3h0HrCzZMVevMMjK0RGZaePENFLfLArsSsEHr1wtKqnqx+qPV2iimIJo2C8Sz3iVx+rJ6YHygcXRPRdm4SojAiJy8BlK4LFn0pXFw0BNtjH/vzkbXiCDeDW8LdL+NDtEr3qo/tUtZQogH9udXz3qqSKPJGks5utvjeuj/5TOQ01PL0NE4Q8CEBUXGV8= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(136003)(396003)(376002)(346002)(39860400002)(230922051799003)(1800799012)(451199024)(186009)(82310400011)(64100799003)(36840700001)(40470700004)(46966006)(4326008)(82740400003)(5660300002)(2906002)(7416002)(478600001)(47076005)(6666004)(83380400001)(426003)(2616005)(26005)(16526019)(336012)(1076003)(36756003)(54906003)(36860700001)(70586007)(70206006)(110136005)(316002)(8676002)(8936002)(81166007)(356005)(41300700001)(40480700001)(40460700003)(26583001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jan 2024 11:49:17.4230 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 077a0f8a-2958-45a4-f464-08dc103fd821 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF000015CA.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB9346 Reading the CDAT table using DOE requires a Table Access Response Header in addition to the CDAT entry. In current implementation this has caused offsets with sizeof(__le32) to the actual buffers. This led to hardly readable code and even bugs (see fix of devm_kfree() in read_cdat_data()). Rework code to avoid calculations with sizeof(__le32). Introduce struct cdat_doe for this which contains the Table Access Response Header and a variable payload size for various data structures afterwards to access the CDAT table and its CDAT Data Structures without recalculating buffer offsets. Cc: Lukas Wunner Cc: Fan Ni Reviewed-by: Dave Jiang Signed-off-by: Robert Richter --- drivers/cxl/core/pci.c | 67 +++++++++++++++++++++--------------------- drivers/cxl/cxlpci.h | 19 ++++++++++++ 2 files changed, 53 insertions(+), 33 deletions(-) diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c index 89bab00bb291..75d8fa228879 100644 --- a/drivers/cxl/core/pci.c +++ b/drivers/cxl/core/pci.c @@ -544,55 +544,53 @@ static int cxl_cdat_get_length(struct device *dev, static int cxl_cdat_read_table(struct device *dev, struct pci_doe_mb *doe_mb, - void *cdat_table, size_t *cdat_length) + struct cdat_doe_rsp *rsp, size_t *length) { - size_t length = *cdat_length + sizeof(__le32); - __le32 *data = cdat_table; + size_t received, remaining = *length; int entry_handle = 0; __le32 saved_dw = 0; do { __le32 request = CDAT_DOE_REQ(entry_handle); - struct cdat_entry_header *entry; - size_t entry_dw; int rc; rc = pci_doe(doe_mb, PCI_DVSEC_VENDOR_ID_CXL, CXL_DOE_PROTOCOL_TABLE_ACCESS, &request, sizeof(request), - data, length); + rsp, sizeof(*rsp) + remaining); if (rc < 0) { dev_err(dev, "DOE failed: %d", rc); return rc; } - /* 1 DW Table Access Response Header + CDAT entry */ - entry = (struct cdat_entry_header *)(data + 1); + if (rc < sizeof(*rsp)) + return -EIO; + + received = rc - sizeof(*rsp); + if ((entry_handle == 0 && - rc != sizeof(__le32) + sizeof(struct cdat_header)) || + received != sizeof(rsp->header[0])) || (entry_handle > 0 && - (rc < sizeof(__le32) + sizeof(*entry) || - rc != sizeof(__le32) + le16_to_cpu(entry->length)))) + (received < sizeof(rsp->entry[0]) || + received != le16_to_cpu(rsp->entry->length)))) return -EIO; /* Get the CXL table access header entry handle */ entry_handle = FIELD_GET(CXL_DOE_TABLE_ACCESS_ENTRY_HANDLE, - le32_to_cpu(data[0])); - entry_dw = rc / sizeof(__le32); - /* Skip Header */ - entry_dw -= 1; + le32_to_cpu(rsp->doe_header)); + /* * Table Access Response Header overwrote the last DW of * previous entry, so restore that DW */ - *data = saved_dw; - length -= entry_dw * sizeof(__le32); - data += entry_dw; - saved_dw = *data; + rsp->doe_header = saved_dw; + remaining -= received; + rsp = (void *)rsp + received; + saved_dw = rsp->doe_header; } while (entry_handle != CXL_DOE_TABLE_ACCESS_LAST_ENTRY); /* Length in CDAT header may exceed concatenation of CDAT entries */ - *cdat_length -= length - sizeof(__le32); + *length -= remaining; return 0; } @@ -620,8 +618,8 @@ void read_cdat_data(struct cxl_port *port) struct pci_doe_mb *doe_mb; struct pci_dev *pdev = NULL; struct cxl_memdev *cxlmd; - size_t cdat_length; - void *cdat_table, *cdat_buf; + struct cdat_doe_rsp *buf; + size_t length; int rc; if (is_cxl_memdev(uport)) { @@ -647,30 +645,33 @@ void read_cdat_data(struct cxl_port *port) port->cdat_available = true; - if (cxl_cdat_get_length(dev, doe_mb, &cdat_length)) { + if (cxl_cdat_get_length(dev, doe_mb, &length)) { dev_dbg(dev, "No CDAT length\n"); return; } - cdat_buf = devm_kzalloc(dev, cdat_length + sizeof(__le32), GFP_KERNEL); - if (!cdat_buf) - return; + /* + * The begin of the CDAT buffer needs space for additional 4 + * bytes for the DOE header. Table data starts afterwards. + */ + buf = devm_kzalloc(dev, sizeof(*buf) + length, GFP_KERNEL); + if (!buf) + goto err; - rc = cxl_cdat_read_table(dev, doe_mb, cdat_buf, &cdat_length); + rc = cxl_cdat_read_table(dev, doe_mb, buf, &length); if (rc) goto err; - cdat_table = cdat_buf + sizeof(__le32); - if (cdat_checksum(cdat_table, cdat_length)) + if (cdat_checksum(buf->table, length)) goto err; - port->cdat.table = cdat_table; - port->cdat.length = cdat_length; - return; + port->cdat.table = buf->table; + port->cdat.length = length; + return; err: /* Don't leave table data allocated on error */ - devm_kfree(dev, cdat_buf); + devm_kfree(dev, buf); dev_err(dev, "Failed to read/validate CDAT.\n"); } EXPORT_SYMBOL_NS_GPL(read_cdat_data, CXL); diff --git a/drivers/cxl/cxlpci.h b/drivers/cxl/cxlpci.h index 711b05d9a370..b40c571b2ab2 100644 --- a/drivers/cxl/cxlpci.h +++ b/drivers/cxl/cxlpci.h @@ -85,6 +85,25 @@ struct cdat_entry_header { __le16 length; } __packed; +/* + * Response contains the CDAT only response header of the DOE. The + * response payload is a CDAT structure (either CDAT header or entry), + * it may also mark the beginning of the CDAT table. + * + * Spec refs: + * + * CXL 3.1 Table 8-14: Read Entry Response + * CDAT Specification 1.03: 2 CDAT Data Structures + */ +struct cdat_doe_rsp { + __le32 doe_header; + union { + DECLARE_FLEX_ARRAY(u8, table); + DECLARE_FLEX_ARRAY(struct cdat_header, header); + DECLARE_FLEX_ARRAY(struct cdat_entry_header, entry); + }; +} __packed; + /* * CXL v3.0 6.2.3 Table 6-4 * The table indicates that if PCIe Flit Mode is set, then CXL is in 256B flits From patchwork Mon Jan 8 11:48:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Richter X-Patchwork-Id: 13513329 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2062.outbound.protection.outlook.com [40.107.223.62]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B1712575D; Mon, 8 Jan 2024 11:50:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="ql2SB+TV" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bjmPQ4OdHAkQn+C/6Z1dCdj/MfhAOX9pvylUeyMbCoLsY5uANU46yDLcGeLoKTjY5ZeEqBzwgNVbFHSvzLvicQt4eV4cRE0Yt+JC4LQC/WlVxU8zR+doHyv9EJZ/1zvsf1bwQOvySIxQKxa+CdibWA5lWgIk3YThxADm6pftWUZgANX/hTqs5ecSd1mKjrPhsyMoMkGveOKOnuAi7vx+9l7FeOe3Qb4kttoFH16gzYlF9Y8JMai7DoFfouhMGGTYxevkBP9M0q/FmV9lBsx+ehPsWPP8rj8j64aOJQSl8hxhCvuprH8Z72Cf8Lu4bgBx48NiugN5enSpHsiJDiMqKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=79adfbqzxe7Iw/HSPcanom0+XiQ5cw74aFMumeN2m1Y=; b=kSVnTXY/RLIBZeBW34sl7UGr4ABqhPJeMIgWAGwx7dim9SffnH05ThEJHXygPq4ATyZyQAq12dFEAt3CNzXggA33GSl4pLwPAU3Miw6f7zJiDEf2QSpse08cua8afzYCOzI+6qkgsvsudjzusn73GmjWFq3BxqtV7w6yNWF0P4c4k8A0CVuKCUKAHHurIMp5b5c7oDCIgCMoY0IZBCBPqSUT/GcAqqa0Xts85jEDVyj3QRkHRVGgpGAFitqZnPShqoDZXmWx0cZ3AopX2uuApH8FVeo3tUuv+TR3fp2w5nScNqaVDWpIjps09YKIwpTjN8HZG0ZH60RfUV6NUc/m0g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=79adfbqzxe7Iw/HSPcanom0+XiQ5cw74aFMumeN2m1Y=; b=ql2SB+TVTFZYzZ9hOWh1HRhbW/LVGcmGPmOBFHOWgdVRQt21/+pRXbSXofdkwUCed4FFNKeVEkhWF/ZrIkry8adOUZXgT+j0DXwvQuDXDQFjLHcRP35RQuCOYVOh5FnZ96jhxX0OOsD8/5ryjFEeZu7+jw4qKvLAp1oGzdawPNQ= Received: from PH8PR02CA0007.namprd02.prod.outlook.com (2603:10b6:510:2d0::18) by IA0PR12MB7529.namprd12.prod.outlook.com (2603:10b6:208:441::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.21; Mon, 8 Jan 2024 11:50:10 +0000 Received: from SA2PEPF000015C8.namprd03.prod.outlook.com (2603:10b6:510:2d0:cafe::fa) by PH8PR02CA0007.outlook.office365.com (2603:10b6:510:2d0::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.23 via Frontend Transport; Mon, 8 Jan 2024 11:50:09 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SA2PEPF000015C8.mail.protection.outlook.com (10.167.241.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7181.13 via Frontend Transport; Mon, 8 Jan 2024 11:50:09 +0000 Received: from rric.localdomain (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Mon, 8 Jan 2024 05:49:18 -0600 From: Robert Richter To: Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Jonathan Cameron , Dave Jiang , Davidlohr Bueso , "Rafael J. Wysocki" , Andrew Morton CC: , , Len Brown , Robert Richter , Subject: [PATCH v2 3/3] lib/firmware_table: Provide buffer length argument to cdat_table_parse() Date: Mon, 8 Jan 2024 12:48:33 +0100 Message-ID: <20240108114833.241710-4-rrichter@amd.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240108114833.241710-1-rrichter@amd.com> References: <20240108114833.241710-1-rrichter@amd.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF000015C8:EE_|IA0PR12MB7529:EE_ X-MS-Office365-Filtering-Correlation-Id: 26138389-7e54-476e-6f9b-08dc103ff74f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ONRBZRRak85LIQFJAA4VovCD/FLT2K7so3VdYEUjHOBc1G8Bog94niROSFMN28gMG3Ja2mkugX0mDcTewDOeF/CodiiYsWfQFHY1Bazted5HNTiQFgRhg1643N0RZ0WZtwltLmGk839fUj71o75HW+wkU8vRYVd0AzY7YmbKj2syx/Vg8oTQoHFtOvlugm2hgQTHDNHYXhI7LBN+KtAtwe0BvIqvNSv3/ocjj/1ZGG1G9QnoFvjnO11SFTnYhv/NYLG7Y366Y1ymSvK7I9SdNokcj0phsAhhzEzDX59Hl/IIJoJS/R0hbB5WzpabEP1Ew/A+lDfYbt9JxXnOaCk1Qm3EjYrj6UsYVMoNRMY5QD5qH91ybOrnpffXfAhmmIHZGgpA8YvvGCF8JeQN+aucFPgS+PWwES9e+XNE1D1xIYAQNSDq1JVhc6VMsqcR7DwKjriTrPvab3uEYKUiJ8YXS2rJrJdgMImxI67ZzHW2Pd811O8rCPdufeU/qxyIBj1FMsHgB3raZVaBcwNwV7SbPUTcUnJf+vlTKz/Hp5Ma1Sh/4m8OaBBEQeTIxPX0zIN6ocZDAlRg9upSHucJt7f401bNZ1m+kdahzZ5qPSVbyWg6Kep2nCwOnjY98XE+KQh1iQcgZdHvobC2rd2CCrLauut9gzYUEGBX0/6FIIS9r8S0aDrw+MvXWZWO0uKBplQQG6E+odtoPVZhTtB+FltvtJEE+/WSzNIOJ0dvX9Y/Ul+fG4kWM7z/HTUvxYuSL8/j3A13qHrq2D3XUo3ZgFcZ4w== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(136003)(376002)(346002)(39860400002)(396003)(230922051799003)(451199024)(64100799003)(186009)(1800799012)(82310400011)(46966006)(40470700004)(36840700001)(36860700001)(6666004)(478600001)(40480700001)(82740400003)(47076005)(40460700003)(81166007)(356005)(83380400001)(26005)(426003)(336012)(16526019)(2616005)(8936002)(8676002)(110136005)(7416002)(316002)(54906003)(5660300002)(2906002)(4326008)(36756003)(70206006)(70586007)(1076003)(41300700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jan 2024 11:50:09.7305 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 26138389-7e54-476e-6f9b-08dc103ff74f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF000015C8.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7529 The last entry in the CDAT table may not mark the end of the CDAT table buffer specified by the length field in the CDAT header. It can be shorter with trailing unused (zero'ed) data. The actual table length is determined when reading all CDAT entries of the table with DOE. If the table is greater than expected (containing zero'ed trailing data), the CDAT parser fails with: [ 48.691717] Malformed DSMAS table length: (24:0) [ 48.702084] [CDAT:0x00] Invalid zero length [ 48.711460] cxl_port endpoint1: Failed to parse CDAT: -22 In addition, the table buffer size can be different from the size specified in the length field. This may cause out-of-bound access then parsing the CDAT table. Fix that by providing an optonal buffer length argument to acpi_parse_entries_array() that can be used by cdat_table_parse() to propagate the buffer size down to its users. Cc: "Rafael J. Wysocki" Cc: Len Brown Signed-off-by: Robert Richter Reviewed-by: Dave Jiang --- drivers/acpi/tables.c | 2 +- drivers/cxl/core/cdat.c | 6 +++--- include/linux/fw_table.h | 4 +++- lib/fw_table.c | 15 ++++++++++----- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index b07f7d091d13..b976e5fc3fbc 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -253,7 +253,7 @@ int __init_or_acpilib acpi_table_parse_entries_array( count = acpi_parse_entries_array(id, table_size, (union fw_table_header *)table_header, - proc, proc_num, max_entries); + 0, proc, proc_num, max_entries); acpi_put_table(table_header); return count; diff --git a/drivers/cxl/core/cdat.c b/drivers/cxl/core/cdat.c index 6fe11546889f..012d8f2a7945 100644 --- a/drivers/cxl/core/cdat.c +++ b/drivers/cxl/core/cdat.c @@ -149,13 +149,13 @@ static int cxl_cdat_endpoint_process(struct cxl_port *port, int rc; rc = cdat_table_parse(ACPI_CDAT_TYPE_DSMAS, cdat_dsmas_handler, - dsmas_xa, port->cdat.table); + dsmas_xa, port->cdat.table, port->cdat.length); rc = cdat_table_parse_output(rc); if (rc) return rc; rc = cdat_table_parse(ACPI_CDAT_TYPE_DSLBIS, cdat_dslbis_handler, - dsmas_xa, port->cdat.table); + dsmas_xa, port->cdat.table, port->cdat.length); return cdat_table_parse_output(rc); } @@ -511,7 +511,7 @@ void cxl_switch_parse_cdat(struct cxl_port *port) return; rc = cdat_table_parse(ACPI_CDAT_TYPE_SSLBIS, cdat_sslbis_handler, - port, port->cdat.table); + port, port->cdat.table, port->cdat.length); rc = cdat_table_parse_output(rc); if (rc) dev_dbg(&port->dev, "Failed to parse SSLBIS: %d\n", rc); diff --git a/include/linux/fw_table.h b/include/linux/fw_table.h index 95421860397a..3ff4c277296f 100644 --- a/include/linux/fw_table.h +++ b/include/linux/fw_table.h @@ -40,12 +40,14 @@ union acpi_subtable_headers { int acpi_parse_entries_array(char *id, unsigned long table_size, union fw_table_header *table_header, + unsigned long max_length, struct acpi_subtable_proc *proc, int proc_num, unsigned int max_entries); int cdat_table_parse(enum acpi_cdat_type type, acpi_tbl_entry_handler_arg handler_arg, void *arg, - struct acpi_table_cdat *table_header); + struct acpi_table_cdat *table_header, + unsigned long length); /* CXL is the only non-ACPI consumer of the FIRMWARE_TABLE library */ #if IS_ENABLED(CONFIG_ACPI) && !IS_ENABLED(CONFIG_CXL_BUS) diff --git a/lib/fw_table.c b/lib/fw_table.c index 1e5e0b2f7012..ddb67853b7ac 100644 --- a/lib/fw_table.c +++ b/lib/fw_table.c @@ -132,6 +132,7 @@ static __init_or_fwtbl_lib int call_handler(struct acpi_subtable_proc *proc, * * @id: table id (for debugging purposes) * @table_size: size of the root table + * @max_length: maximum size of the table (ignore if 0) * @table_header: where does the table start? * @proc: array of acpi_subtable_proc struct containing entry id * and associated handler with it @@ -153,10 +154,11 @@ static __init_or_fwtbl_lib int call_handler(struct acpi_subtable_proc *proc, int __init_or_fwtbl_lib acpi_parse_entries_array(char *id, unsigned long table_size, union fw_table_header *table_header, + unsigned long max_length, struct acpi_subtable_proc *proc, int proc_num, unsigned int max_entries) { - unsigned long table_end, subtable_len, entry_len; + unsigned long table_len, table_end, subtable_len, entry_len; struct acpi_subtable_entry entry; enum acpi_subtable_type type; int count = 0; @@ -164,8 +166,10 @@ acpi_parse_entries_array(char *id, unsigned long table_size, int i; type = acpi_get_subtable_type(id); - table_end = (unsigned long)table_header + - acpi_table_get_length(type, table_header); + table_len = acpi_table_get_length(type, table_header); + if (max_length && max_length < table_len) + table_len = max_length; + table_end = (unsigned long)table_header + table_len; /* Parse all entries looking for a match. */ @@ -220,7 +224,8 @@ int __init_or_fwtbl_lib cdat_table_parse(enum acpi_cdat_type type, acpi_tbl_entry_handler_arg handler_arg, void *arg, - struct acpi_table_cdat *table_header) + struct acpi_table_cdat *table_header, + unsigned long length) { struct acpi_subtable_proc proc = { .id = type, @@ -234,6 +239,6 @@ cdat_table_parse(enum acpi_cdat_type type, return acpi_parse_entries_array(ACPI_SIG_CDAT, sizeof(struct acpi_table_cdat), (union fw_table_header *)table_header, - &proc, 1, 0); + length, &proc, 1, 0); } EXPORT_SYMBOL_FWTBL_LIB(cdat_table_parse);