]> git.proxmox.com Git - mirror_edk2.git/commitdiff
DynamicTablesPkg: Clear pointer in node creation fcts
authorPierre Gondois <Pierre.Gondois@arm.com>
Fri, 8 Oct 2021 14:46:18 +0000 (15:46 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 8 Oct 2021 15:39:42 +0000 (15:39 +0000)
The following functions:
- AmlCreateRootNode()
- AmlCreateObjectNode()
- AmlCreateDataNode()
create a node and return it by populating a pointer. This pointer
should only be considered/used if the function returns successfully.
Otherwise, the value stored in this pointer should be ignored.

For their error handling, some other functions assume that this
pointer is reset to NULL if an error occurs during a node creation.
To make this assumption correct, explicitly clear this input pointer.

Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c
DynamicTablesPkg/Library/Common/AmlLib/Tree/AmlNode.c
DynamicTablesPkg/Library/Common/AmlLib/Tree/AmlNode.h

index 5d310f201319d94ffe6405aeeec65a7038a76c57..4775b68cd974dee89781ba39cc9c789051b88611 100644 (file)
@@ -22,7 +22,9 @@
   @param [in]  Node           Newly created node.\r
   @param [in]  ParentNode     If provided, set ParentNode as the parent\r
                               of the node created.\r
-  @param [out] NewObjectNode  If success, contains the created object node.\r
+  @param [out] NewObjectNode  If not NULL:\r
+                               - and Success, contains the created Node.\r
+                               - and Error, reset to NULL.\r
 \r
   @retval  EFI_SUCCESS            The function completed successfully.\r
   @retval  EFI_INVALID_PARAMETER  Invalid parameter.\r
@@ -39,7 +41,7 @@ LinkNode (
   EFI_STATUS    Status;\r
 \r
   if (NewObjectNode != NULL) {\r
-    *NewObjectNode = Node;\r
+    *NewObjectNode = NULL;\r
   }\r
 \r
   // Add RdNode as the last element.\r
@@ -51,6 +53,10 @@ LinkNode (
     }\r
   }\r
 \r
+  if (NewObjectNode != NULL) {\r
+    *NewObjectNode = Node;\r
+  }\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
index 089597a6c9066d6653851dadbe600860debf70fe..cba942c0fd1a4a251aaf8cd7c0de69cd53867e2a 100644 (file)
@@ -33,7 +33,9 @@
                             RdNode is then added at the end of the variable\r
                             list of resource data elements, but before the\r
                             "End Tag" Resource Data.\r
-  @param [out] NewRdNode    If not NULL, update the its value to RdNode.\r
+  @param [out] NewRdNode    If not NULL:\r
+                             - and Success, contains RdNode.\r
+                             - and Error, reset to NULL.\r
 \r
   @retval  EFI_SUCCESS            The function completed successfully.\r
   @retval  EFI_INVALID_PARAMETER  Invalid parameter.\r
@@ -52,7 +54,7 @@ LinkRdNode (
   AML_OBJECT_NODE   *BufferOpNode;\r
 \r
   if (NewRdNode != NULL) {\r
-    *NewRdNode = RdNode;\r
+    *NewRdNode = NULL;\r
   }\r
 \r
   if (ParentNode != NULL) {\r
@@ -85,6 +87,10 @@ LinkRdNode (
     }\r
   }\r
 \r
+  if (NewRdNode != NULL) {\r
+    *NewRdNode = RdNode;\r
+  }\r
+\r
   return Status;\r
 \r
 error_handler:\r
index 3740c0ac7bb8d2697bc1597dc1030d8276e6f565..300b07a2efe4ff5d659092de33527f950c526a6c 100644 (file)
@@ -79,7 +79,9 @@ AmlDeleteRootNode (
 \r
   @param  [in]  SdtHeader       Pointer to an ACPI DSDT/SSDT header to copy\r
                                 the data from.\r
-  @param  [out] NewRootNodePtr  The created AML_ROOT_NODE.\r
+  @param  [out] NewRootNodePtr  If success, contains the created\r
+                                AML_ROOT_NODE.\r
+                                Otherwise reset to NULL.\r
 \r
   @retval EFI_SUCCESS             The function completed successfully.\r
   @retval EFI_INVALID_PARAMETER   Invalid parameter.\r
@@ -101,6 +103,8 @@ AmlCreateRootNode (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  *NewRootNodePtr = NULL;\r
+\r
   RootNode = AllocateZeroPool (sizeof (AML_ROOT_NODE));\r
   if (RootNode == NULL) {\r
     ASSERT (0);\r
@@ -163,7 +167,9 @@ AmlDeleteObjectNode (
   @param  [in]  PkgLength         PkgLength of the node if the AmlByteEncoding\r
                                   has the PkgLen attribute.\r
                                   0 otherwise.\r
-  @param  [out] NewObjectNodePtr  The created AML_OBJECT_NODE.\r
+  @param  [out] NewObjectNodePtr  If success, contains the created\r
+                                  AML_OBJECT_NODE.\r
+                                  Otherwise reset to NULL.\r
 \r
   @retval EFI_SUCCESS             The function completed successfully.\r
   @retval EFI_INVALID_PARAMETER   Invalid parameter.\r
@@ -186,6 +192,8 @@ AmlCreateObjectNode (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  *NewObjectNodePtr = NULL;\r
+\r
   ObjectNode = AllocateZeroPool (sizeof (AML_OBJECT_NODE));\r
   if (ObjectNode == NULL) {\r
     ASSERT (0);\r
@@ -252,7 +260,9 @@ AmlDeleteDataNode (
                                 this node. Data is copied from there.\r
   @param  [in]  DataSize        Number of bytes to consider at the address\r
                                 pointed by Data.\r
-  @param  [out] NewDataNodePtr  The created AML_DATA_NODE.\r
+  @param  [out] NewDataNodePtr  If success, contains the created\r
+                                AML_DATA_NODE.\r
+                                Otherwise reset to NULL.\r
 \r
   @retval EFI_SUCCESS             The function completed successfully.\r
   @retval EFI_INVALID_PARAMETER   Invalid parameter.\r
@@ -284,6 +294,8 @@ AmlCreateDataNode (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  *NewDataNodePtr = NULL;\r
+\r
   DataNode = AllocateZeroPool (sizeof (AML_DATA_NODE));\r
   if (DataNode == NULL) {\r
     ASSERT (0);\r
index 3584b572baae5d48f5016c0b889f557c5ba94d07..465a0e2b4b2f9ad9b2b3851add6af1c3d02d4f76 100644 (file)
@@ -17,7 +17,9 @@
 \r
   @param  [in]  SdtHeader       Pointer to an ACPI DSDT/SSDT header to copy\r
                                 the data from.\r
-  @param  [out] NewRootNodePtr  The created AML_ROOT_NODE.\r
+  @param  [out] NewRootNodePtr  If success, contains the created\r
+                                AML_ROOT_NODE.\r
+                                Otherwise reset to NULL.\r
 \r
   @retval EFI_SUCCESS             The function completed successfully.\r
   @retval EFI_INVALID_PARAMETER   Invalid parameter.\r
@@ -36,7 +38,9 @@ AmlCreateRootNode (
   @param  [in]  PkgLength         PkgLength of the node if the AmlByteEncoding\r
                                   has the PkgLen attribute.\r
                                   0 otherwise.\r
-  @param  [out] NewObjectNodePtr  The created AML_OBJECT_NODE.\r
+  @param  [out] NewObjectNodePtr  If success, contains the created\r
+                                  AML_OBJECT_NODE.\r
+                                  Otherwise reset to NULL.\r
 \r
   @retval EFI_SUCCESS             The function completed successfully.\r
   @retval EFI_INVALID_PARAMETER   Invalid parameter.\r
@@ -57,7 +61,9 @@ AmlCreateObjectNode (
                                 this node. Data is copied from there.\r
   @param  [in]  DataSize        Number of bytes to consider at the address\r
                                 pointed by Data.\r
-  @param  [out] NewDataNodePtr  The created AML_DATA_NODE.\r
+  @param  [out] NewDataNodePtr  If success, contains the created\r
+                                AML_DATA_NODE.\r
+                                Otherwise reset to NULL.\r
 \r
   @retval EFI_SUCCESS             The function completed successfully.\r
   @retval EFI_INVALID_PARAMETER   Invalid parameter.\r