[NDK][NTOS] Add global definition of INIT_FUNCTION/INIT_SECTION (#779)
[reactos.git] / ntoskrnl / config / cmconfig.c
index f483d70..be46cfe 100644 (file)
@@ -14,9 +14,9 @@
 
 /* FUNCTIONS *****************************************************************/
 
+INIT_FUNCTION
 NTSTATUS
 NTAPI
-INIT_FUNCTION
 CmpInitializeRegistryNode(IN PCONFIGURATION_COMPONENT_DATA CurrentEntry,
                           IN HANDLE NodeHandle,
                           OUT PHANDLE NewHandle,
@@ -67,7 +67,12 @@ CmpInitializeRegistryNode(IN PCONFIGURATION_COMPONENT_DATA CurrentEntry,
 
         /* Convert it to Unicode */
         RtlInitEmptyUnicodeString(&KeyName, Buffer, sizeof(Buffer));
-        RtlAnsiStringToUnicodeString(&KeyName, &TempString, FALSE);
+        Status = RtlAnsiStringToUnicodeString(&KeyName, &TempString, FALSE);
+        if (!NT_SUCCESS(Status))
+        {
+            NtClose(KeyHandle);
+            return Status;
+        }
 
         /* Create the key */
         ParentHandle = KeyHandle;
@@ -148,7 +153,7 @@ CmpInitializeRegistryNode(IN PCONFIGURATION_COMPONENT_DATA CurrentEntry,
                  FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList);
         if (Length > CmpConfigurationAreaSize)
         {
-            ASSERTMSG("Component too large -- need reallocation!", FALSE);
+            ASSERTMSG("Component too large -- need reallocation!\n", FALSE);
         }
         else
         {
@@ -194,9 +199,9 @@ CmpInitializeRegistryNode(IN PCONFIGURATION_COMPONENT_DATA CurrentEntry,
     return Status;
 }
 
+INIT_FUNCTION
 NTSTATUS
 NTAPI
-INIT_FUNCTION
 CmpSetupConfigurationTree(IN PCONFIGURATION_COMPONENT_DATA CurrentEntry,
                           IN HANDLE ParentHandle,
                           IN INTERFACE_TYPE InterfaceType,
@@ -221,23 +226,25 @@ CmpSetupConfigurationTree(IN PCONFIGURATION_COMPONENT_DATA CurrentEntry,
             {
                 /* EISA */
                 case EisaAdapter:
-                    
+                {
                     /* Fixup information */
                     Interface = Eisa;
                     Bus = CmpTypeCount[EisaAdapter]++;
                     break;
+                }
 
                 /* Turbo-channel */
                 case TcAdapter:
-                    
+                {
                     /* Fixup information */
                     Interface = TurboChannel;
                     Bus = CmpTypeCount[TurboChannel]++;
                     break;
+                }
 
                 /* ISA, PCI, etc busses */
                 case MultiFunctionAdapter:
-                    
+                {
                     /* Check if we have an  identifier */
                     if (Component->Identifier)
                     {
@@ -252,29 +259,33 @@ CmpSetupConfigurationTree(IN PCONFIGURATION_COMPONENT_DATA CurrentEntry,
                                 break;
                             }
                         }
-                        
+
                         /* Fix up information */
                         Interface = CmpMultifunctionTypes[i].InterfaceType;
                         Bus = CmpMultifunctionTypes[i].Count++;
                     }
                     break;
+                }
 
                 /* SCSI Bus */
                 case ScsiAdapter:
-                    
+                {
                     /* Fix up */
                     Interface = Internal;
                     Bus = CmpTypeCount[ScsiAdapter]++;
                     break;
+                }
 
                 /* Unknown */
                 default:
+                {
                     Interface = -1;
                     Bus = CmpUnknownBusCount++;
                     break;
+                }
             }
         }
-        
+
         /* Dump information on the component */
 
         /* Setup the hardware node */
@@ -285,7 +296,7 @@ CmpSetupConfigurationTree(IN PCONFIGURATION_COMPONENT_DATA CurrentEntry,
                                            Bus,
                                            DeviceIndexTable);
         if (!NT_SUCCESS(Status)) return Status;
-        
+
         /* Check for children */
         if (CurrentEntry->Child)
         {
@@ -301,19 +312,19 @@ CmpSetupConfigurationTree(IN PCONFIGURATION_COMPONENT_DATA CurrentEntry,
                 return Status;
             }
         }
-        
+
         /* Get to the next entry */
         NtClose(NewHandle);
         CurrentEntry = CurrentEntry->Sibling;
     }
-    
+
     /* We're done */
     return STATUS_SUCCESS;
 }
 
+INIT_FUNCTION
 NTSTATUS
 NTAPI
-INIT_FUNCTION
 CmpInitializeHardwareConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 {
     NTSTATUS Status;
@@ -339,7 +350,8 @@ CmpInitializeHardwareConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
                          NULL,
                          0,
                          &Disposition);
-    if (!NT_SUCCESS(Status)) return Status;
+    if (!NT_SUCCESS(Status))
+        return Status;
     NtClose(KeyHandle);
 
     /* Nobody should've created this key yet! */
@@ -362,7 +374,8 @@ CmpInitializeHardwareConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
                           NULL,
                           0,
                           &Disposition);
-    if (!NT_SUCCESS(Status)) return Status;
+    if (!NT_SUCCESS(Status))
+        return Status;
 
     /* Nobody should've created this key yet! */
     ASSERT(Disposition == REG_CREATED_NEW_KEY);
@@ -371,7 +384,11 @@ CmpInitializeHardwareConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
     CmpConfigurationData = ExAllocatePoolWithTag(PagedPool,
                                                  CmpConfigurationAreaSize,
                                                  TAG_CM);
-    if (!CmpConfigurationData) return STATUS_INSUFFICIENT_RESOURCES;
+    if (!CmpConfigurationData)
+    {
+        NtClose(KeyHandle);
+        return STATUS_INSUFFICIENT_RESOURCES;
+    }
 
     /* Check if we got anything from NTLDR */
     if (LoaderBlock->ConfigurationRoot)
@@ -388,7 +405,7 @@ CmpInitializeHardwareConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
         Status = STATUS_SUCCESS;
     }
 
-    /* Close our handle, free the buffer and return status */
+    /* Free the buffer, close our handle and return status */
     ExFreePoolWithTag(CmpConfigurationData, TAG_CM);
     NtClose(KeyHandle);
     return Status;