public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Sami Mujawar" <sami.mujawar@arm.com>
To: <devel@edk2.groups.io>
Cc: Sami Mujawar <sami.mujawar@arm.com>, <Alexei.Fedorov@arm.com>,
	<pierre.gondois@arm.com>, <Matteo.Carlini@arm.com>,
	<Akanksha.Jain2@arm.com>, <Ben.Adderson@arm.com>, <nd@arm.com>
Subject: [PATCH v6 2/8] DynamicTablesPkg: Handle error when IdMappingToken is NULL
Date: Thu, 14 Jul 2022 17:50:25 +0100	[thread overview]
Message-ID: <20220714165031.42640-3-sami.mujawar@arm.com> (raw)
In-Reply-To: <20220714165031.42640-1-sami.mujawar@arm.com>

Add error handling when the IdMappingCount is not zero and the
IdMappingToken is NULL.

Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
---

Notes:
    v6:
     - No changes since v3. Resending with v6 series.              [SAMI]
    
    v5:
     - No changes since v3. Resending with v5 series.              [SAMI]
    
    v4:
     - No changes since v3. Resending with v4 series.              [SAMI]
    v3:
     - New patch in this series. Moves error handling code for     [SAMI]
       IdMappingToken from patch v2 6/8 and v2 8/8 into this
       patch.
       Ref: https://edk2.groups.io/g/devel/topic/83600728#76662
            https://edk2.groups.io/g/devel/topic/83600726#76661

 DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGenerator.c | 82 ++++++++++++++++----
 1 file changed, 66 insertions(+), 16 deletions(-)

diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGenerator.c
index 0f13c32b838bf4fe42b53a1e9c3ce817d74681fb..daf9ff00c3deab4005814bbfcf1650469d1e7d92 100644
--- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGenerator.c
+++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGenerator.c
@@ -1,7 +1,7 @@
 /** @file
   IORT Table Generator
 
-  Copyright (c) 2017 - 2020, ARM Limited. All rights reserved.
+  Copyright (c) 2017 - 2022, Arm Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Reference(s):
@@ -905,9 +905,19 @@ AddNamedComponentNodes (
       return Status;
     }
 
-    if ((NodeList->IdMappingCount > 0) &&
-        (NodeList->IdMappingToken != CM_NULL_TOKEN))
-    {
+    if (NodeList->IdMappingCount > 0) {
+      if (NodeList->IdMappingToken == CM_NULL_TOKEN) {
+        Status = EFI_INVALID_PARAMETER;
+        DEBUG ((
+          DEBUG_ERROR,
+          "ERROR: IORT: Invalid Id Mapping token,"
+          " Token = 0x%x, Status =%r\n",
+          NodeList->IdMappingToken,
+          Status
+          ));
+        return Status;
+      }
+
       // Ids for Named Component
       IdMapArray = (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE *)((UINT8 *)NcNode +
                                                           NcNode->Node.IdReference);
@@ -1011,9 +1021,19 @@ AddRootComplexNodes (
     RcNode->Reserved1[1]      = EFI_ACPI_RESERVED_BYTE;
     RcNode->Reserved1[2]      = EFI_ACPI_RESERVED_BYTE;
 
-    if ((NodeList->IdMappingCount > 0) &&
-        (NodeList->IdMappingToken != CM_NULL_TOKEN))
-    {
+    if (NodeList->IdMappingCount > 0) {
+      if (NodeList->IdMappingToken == CM_NULL_TOKEN) {
+        Status = EFI_INVALID_PARAMETER;
+        DEBUG ((
+          DEBUG_ERROR,
+          "ERROR: IORT: Invalid Id Mapping token,"
+          " Token = 0x%x, Status =%r\n",
+          NodeList->IdMappingToken,
+          Status
+          ));
+        return Status;
+      }
+
       // Ids for Root Complex
       IdMapArray = (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE *)((UINT8 *)RcNode +
                                                           RcNode->Node.IdReference);
@@ -1242,9 +1262,19 @@ AddSmmuV1V2Nodes (
       }
     }
 
-    if ((NodeList->IdMappingCount > 0) &&
-        (NodeList->IdMappingToken != CM_NULL_TOKEN))
-    {
+    if (NodeList->IdMappingCount > 0) {
+      if (NodeList->IdMappingToken == CM_NULL_TOKEN) {
+        Status = EFI_INVALID_PARAMETER;
+        DEBUG ((
+          DEBUG_ERROR,
+          "ERROR: IORT: Invalid Id Mapping token,"
+          " Token = 0x%x, Status =%r\n",
+          NodeList->IdMappingToken,
+          Status
+          ));
+        return Status;
+      }
+
       // Ids for SMMU v1/v2 Node
       IdMapArray = (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE *)((UINT8 *)SmmuNode +
                                                           SmmuNode->Node.IdReference);
@@ -1361,9 +1391,19 @@ AddSmmuV3Nodes (
       SmmuV3Node->DeviceIdMappingIndex = NodeList->DeviceIdMappingIndex;
     }
 
-    if ((NodeList->IdMappingCount > 0) &&
-        (NodeList->IdMappingToken != CM_NULL_TOKEN))
-    {
+    if (NodeList->IdMappingCount > 0) {
+      if (NodeList->IdMappingToken == CM_NULL_TOKEN) {
+        Status = EFI_INVALID_PARAMETER;
+        DEBUG ((
+          DEBUG_ERROR,
+          "ERROR: IORT: Invalid Id Mapping token,"
+          " Token = 0x%x, Status =%r\n",
+          NodeList->IdMappingToken,
+          Status
+          ));
+        return Status;
+      }
+
       // Ids for SMMUv3 node
       IdMapArray = (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE *)((UINT8 *)SmmuV3Node +
                                                           SmmuV3Node->Node.IdReference);
@@ -1476,9 +1516,19 @@ AddPmcgNodes (
       return Status;
     }
 
-    if ((NodeList->IdMappingCount > 0) &&
-        (NodeList->IdMappingToken != CM_NULL_TOKEN))
-    {
+    if (NodeList->IdMappingCount > 0) {
+      if (NodeList->IdMappingToken == CM_NULL_TOKEN) {
+        Status = EFI_INVALID_PARAMETER;
+        DEBUG ((
+          DEBUG_ERROR,
+          "ERROR: IORT: Invalid Id Mapping token,"
+          " Token = 0x%x, Status =%r\n",
+          NodeList->IdMappingToken,
+          Status
+          ));
+        return Status;
+      }
+
       // Ids for PMCG node
       IdMapArray = (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE *)((UINT8 *)PmcgNode +
                                                           PmcgNode->Node.IdReference);
-- 
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'


  parent reply	other threads:[~2022-07-14 16:51 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-14 16:50 [PATCH v6 0/8] IORT Rev E.d specification updates Sami Mujawar
2022-07-14 16:50 ` [PATCH v6 1/8] ShellPkg: Acpiview: Abbreviate field names to preserve alignment Sami Mujawar
2022-07-19  1:46   ` Gao, Zhichao
2022-07-14 16:50 ` Sami Mujawar [this message]
2022-07-14 16:50 ` [PATCH v6 3/8] DynamicTablesPkg: IORT set reference to Id array only if present Sami Mujawar
2022-07-14 16:50 ` [PATCH v6 4/8] DynamicTablesPkg: IORT set reference to interrupt array " Sami Mujawar
2022-07-14 16:50 ` [PATCH v6 5/8] MdePkg: IORT header update for IORT Rev E.d spec Sami Mujawar
2022-07-19  1:46   ` [edk2-devel] " Gao, Zhichao
2022-07-14 16:50 ` [PATCH v6 6/8] ShellPkg: Acpiview: IORT parser " Sami Mujawar
2022-07-18  8:48   ` Sami Mujawar
2022-07-19  1:59   ` [edk2-devel] " Gao, Zhichao
2022-07-14 16:50 ` [PATCH v6 7/8] DynamicTablesPkg: Update ArmNameSpaceObjects for IORT Rev E.d Sami Mujawar
2022-07-14 16:50 ` [PATCH v6 8/8] DynamicTablesPkg: IORT generator updates for Rev E.d spec Sami Mujawar
2022-07-18  7:42 ` [PATCH v6 0/8] IORT Rev E.d specification updates PierreGondois

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220714165031.42640-3-sami.mujawar@arm.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox