]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c
Update code logic, remove ASSERT and use error handling.
[mirror_edk2.git] / MdeModulePkg / Universal / DriverSampleDxe / DriverSample.c
index d79a81a6d9de2e55a2cbcf8620b96f50470a62c3..10eef05098e0c04779a18c8ad821db6d9502600a 100644 (file)
@@ -2,7 +2,7 @@
 This is an example of how a driver might export data to the HII protocol to be\r
 later utilized by the Setup Protocol\r
 \r
 This is an example of how a driver might export data to the HII protocol to be\r
 later utilized by the Setup Protocol\r
 \r
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -1981,25 +1981,40 @@ DriverSampleInit (
                     sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
                     Configuration\r
                     );\r
                     sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
                     Configuration\r
                     );\r
-    ASSERT (Status == EFI_SUCCESS);\r
+    if (EFI_ERROR (Status)) {\r
+      DriverSampleUnload (ImageHandle);\r
+      return Status;\r
+    }\r
     //\r
     // EFI variable for NV config doesn't exit, we should build this variable\r
     // based on default values stored in IFR\r
     //\r
     ActionFlag = HiiSetToDefaults (NameRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);\r
     //\r
     // EFI variable for NV config doesn't exit, we should build this variable\r
     // based on default values stored in IFR\r
     //\r
     ActionFlag = HiiSetToDefaults (NameRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);\r
-    ASSERT (ActionFlag);\r
+    if (!ActionFlag) {\r
+      DriverSampleUnload (ImageHandle);\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
 \r
     ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);\r
 \r
     ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);\r
-    ASSERT (ActionFlag);\r
+    if (!ActionFlag) {\r
+      DriverSampleUnload (ImageHandle);\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
   } else {\r
     //\r
     // EFI variable does exist and Validate Current Setting\r
     //\r
     ActionFlag = HiiValidateSettings (NameRequestHdr);\r
   } else {\r
     //\r
     // EFI variable does exist and Validate Current Setting\r
     //\r
     ActionFlag = HiiValidateSettings (NameRequestHdr);\r
-    ASSERT (ActionFlag);\r
+    if (!ActionFlag) {\r
+      DriverSampleUnload (ImageHandle);\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
 \r
     ActionFlag = HiiValidateSettings (ConfigRequestHdr);\r
 \r
     ActionFlag = HiiValidateSettings (ConfigRequestHdr);\r
-    ASSERT (ActionFlag);\r
+    if (!ActionFlag) {\r
+      DriverSampleUnload (ImageHandle);\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
   }\r
   FreePool (ConfigRequestHdr);\r
 \r
   }\r
   FreePool (ConfigRequestHdr);\r
 \r
@@ -2025,19 +2040,28 @@ DriverSampleInit (
                     sizeof (MY_EFI_VARSTORE_DATA),\r
                     VarStoreConfig\r
                     );\r
                     sizeof (MY_EFI_VARSTORE_DATA),\r
                     VarStoreConfig\r
                     );\r
-    ASSERT (Status == EFI_SUCCESS);\r
+    if (EFI_ERROR (Status)) {\r
+      DriverSampleUnload (ImageHandle);\r
+      return Status;\r
+    }\r
     //\r
     // EFI variable for NV config doesn't exit, we should build this variable\r
     // based on default values stored in IFR\r
     //\r
     ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);\r
     //\r
     // EFI variable for NV config doesn't exit, we should build this variable\r
     // based on default values stored in IFR\r
     //\r
     ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);\r
-    ASSERT (ActionFlag);\r
+    if (!ActionFlag) {\r
+      DriverSampleUnload (ImageHandle);\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
   } else {\r
     //\r
     // EFI variable does exist and Validate Current Setting\r
     //\r
     ActionFlag = HiiValidateSettings (ConfigRequestHdr);\r
   } else {\r
     //\r
     // EFI variable does exist and Validate Current Setting\r
     //\r
     ActionFlag = HiiValidateSettings (ConfigRequestHdr);\r
-    ASSERT (ActionFlag);\r
+    if (!ActionFlag) {\r
+      DriverSampleUnload (ImageHandle);\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
   }\r
   FreePool (ConfigRequestHdr);\r
 \r
   }\r
   FreePool (ConfigRequestHdr);\r
 \r