]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/Ip4Dxe: return error on memory allocate failure instead of ASSERT.
authorFu Siyuan <siyuan.fu@intel.com>
Wed, 13 Dec 2017 02:42:42 +0000 (10:42 +0800)
committerFu Siyuan <siyuan.fu@intel.com>
Mon, 18 Dec 2017 00:53:50 +0000 (08:53 +0800)
This patch updates the IP4 driver to use error status code instead of ASSERT
if failed to allocate memory buffer.

Reviewed-by: Ye Ting <ting.ye@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu Siyuan <siyuan.fu@intel.com>
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c

index c8dc6976d751941486435f470b31a1a77f48de43..694a2d0e1f15d93be1c8854d3804d7f70729dabb 100644 (file)
@@ -293,8 +293,12 @@ Ip4Config2IpToStr (
   @param[in]   IpCount   The size of IPv4 address list.\r
   @param[out]  Str       The string contains several decimal dotted\r
                          IPv4 addresses separated by space.       \r
+\r
+  @retval EFI_SUCCESS           Operation is success.\r
+  @retval EFI_OUT_OF_RESOURCES  Error occurs in allocating memory.\r
+\r
 **/\r
-VOID\r
+EFI_STATUS\r
 Ip4Config2IpListToStr (\r
   IN  EFI_IPv4_ADDRESS  *Ip,\r
   IN  UINTN             IpCount,\r
@@ -317,7 +321,9 @@ Ip4Config2IpListToStr (
     TempIp = Ip + Index;\r
     if (TempStr == NULL) {\r
       TempStr = AllocateZeroPool(2 * IP4_STR_MAX_SIZE);\r
-      ASSERT(TempStr != NULL);\r
+      if (TempStr == NULL) {\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
     }\r
 \r
     UnicodeSPrint (\r
@@ -347,6 +353,8 @@ Ip4Config2IpListToStr (
   if (TempStr != NULL) {\r
     FreePool(TempStr);\r
   }\r
+\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
@@ -518,7 +526,7 @@ Ip4Config2ConvertConfigNvDataToIfrNvData (
   Ip4Config2IpToStr (&Ip4Info->StationAddress, IfrNvData->StationAddress);\r
   Ip4Config2IpToStr (&Ip4Info->SubnetMask, IfrNvData->SubnetMask);\r
   Ip4Config2IpToStr (&GatewayAddress, IfrNvData->GatewayAddress);\r
-  Ip4Config2IpListToStr (DnsAddress, DnsCount, IfrNvData->DnsAddress);\r
+  Status = Ip4Config2IpListToStr (DnsAddress, DnsCount, IfrNvData->DnsAddress);\r
 \r
 Exit:\r
 \r
@@ -914,7 +922,10 @@ Ip4FormExtractConfig (
       ConfigRequestHdr = HiiConstructConfigHdr (&gIp4Config2NvDataGuid, mIp4Config2StorageName, Private->ChildHandle);\r
       Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r
       ConfigRequest = AllocateZeroPool (Size);\r
-      ASSERT (ConfigRequest != NULL);\r
+      if (ConfigRequest == NULL) {\r
+        Status = EFI_OUT_OF_RESOURCES;\r
+        goto Failure;\r
+      }\r
       AllocatedRequest = TRUE;\r
       \r
       UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);\r