Jiaxin,

Is it possible to use goto to handle the error cases instead of duplicating the 
logic?

Thanks,
Ting

-----Original Message-----
From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Jiaxin Wu
Sent: Friday, June 17, 2016 2:46 PM
To: edk2-devel@lists.01.org
Cc: Ye, Ting <ting...@intel.com>; Zhang, Lubo <lubo.zh...@intel.com>; Fu, 
Siyuan <siyuan...@intel.com>
Subject: [edk2] [Patch] NetworkPkg: Replace ASSERT with error handling in DnsDxe

This patch is used to replace ASSERT with error handling in DnsDxe driver.

Cc: Ye Ting <ting...@intel.com>
Cc: Fu Siyuan <siyuan...@intel.com>
Cc: Zhang Lubo <lubo.zh...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiaxin Wu <jiaxin...@intel.com>
---
 NetworkPkg/DnsDxe/DnsProtocol.c | 34 ++++++++++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 4 deletions(-)

diff --git a/NetworkPkg/DnsDxe/DnsProtocol.c b/NetworkPkg/DnsDxe/DnsProtocol.c 
index e9101d6..1102fab 100644
--- a/NetworkPkg/DnsDxe/DnsProtocol.c
+++ b/NetworkPkg/DnsDxe/DnsProtocol.c
@@ -110,11 +110,17 @@ Dns4GetModeData (
   NET_LIST_FOR_EACH_SAFE (Entry, Next, &mDriverData->Dns4ServerList) {
     Index++;
   }
   DnsModeData->DnsServerCount = (UINT32) Index;
   ServerList = AllocatePool (sizeof (EFI_IPv4_ADDRESS) * 
DnsModeData->DnsServerCount);
-  ASSERT (ServerList != NULL);
+  if (ServerList == NULL) {
+    Status = EFI_OUT_OF_RESOURCES;
+    Dns4CleanConfigure (&DnsModeData->DnsConfigData);
+    gBS->RestoreTPL (OldTpl);
+    return Status;
+  }
+  
   Index = 0;
   NET_LIST_FOR_EACH_SAFE (Entry, Next, &mDriverData->Dns4ServerList) {
     ServerItem = NET_LIST_USER_STRUCT (Entry, DNS4_SERVER_IP, AllServerLink);
     CopyMem (ServerList + Index, &ServerItem->Dns4ServerIp, sizeof 
(EFI_IPv4_ADDRESS));
     Index++;
@@ -128,11 +134,18 @@ Dns4GetModeData (
   NET_LIST_FOR_EACH_SAFE (Entry, Next, &mDriverData->Dns4CacheList) {
     Index++;
   }
   DnsModeData->DnsCacheCount = (UINT32) Index;
   CacheList = AllocatePool (sizeof (EFI_DNS4_CACHE_ENTRY) * 
DnsModeData->DnsCacheCount);
-  ASSERT (CacheList != NULL);
+  if (CacheList == NULL) {
+    Status = EFI_OUT_OF_RESOURCES;
+    Dns4CleanConfigure (&DnsModeData->DnsConfigData);
+    FreePool (ServerList);
+    gBS->RestoreTPL (OldTpl);
+    return Status;
+  }
+  
   Index =0;
   NET_LIST_FOR_EACH_SAFE (Entry, Next, &mDriverData->Dns4CacheList) {
     CacheItem = NET_LIST_USER_STRUCT (Entry, DNS4_CACHE, AllCacheLink);
     CopyMem (CacheList + Index, &CacheItem->DnsCache, sizeof 
(EFI_DNS4_CACHE_ENTRY));
     Index++;
@@ -931,11 +944,17 @@ Dns6GetModeData (
   NET_LIST_FOR_EACH_SAFE (Entry, Next, &mDriverData->Dns6ServerList) {
     Index++;
   }
   DnsModeData->DnsServerCount = (UINT32) Index;
   ServerList = AllocatePool (sizeof(EFI_IPv6_ADDRESS) * 
DnsModeData->DnsServerCount);
-  ASSERT (ServerList != NULL);
+  if (ServerList == NULL) {
+    Status = EFI_OUT_OF_RESOURCES;
+    Dns6CleanConfigure (&DnsModeData->DnsConfigData);
+    gBS->RestoreTPL (OldTpl);
+    return Status;
+  }
+  
   Index = 0;
   NET_LIST_FOR_EACH_SAFE (Entry, Next, &mDriverData->Dns6ServerList) {
     ServerItem = NET_LIST_USER_STRUCT (Entry, DNS6_SERVER_IP, AllServerLink);
     CopyMem (ServerList + Index, &ServerItem->Dns6ServerIp, sizeof 
(EFI_IPv6_ADDRESS));
     Index++;
@@ -949,11 +968,18 @@ Dns6GetModeData (
   NET_LIST_FOR_EACH_SAFE (Entry, Next, &mDriverData->Dns6CacheList) {
     Index++;
   }
   DnsModeData->DnsCacheCount = (UINT32) Index;
   CacheList = AllocatePool (sizeof(EFI_DNS6_CACHE_ENTRY) * 
DnsModeData->DnsCacheCount);
-  ASSERT (CacheList != NULL);
+  if (CacheList == NULL) {
+    Status = EFI_OUT_OF_RESOURCES;
+    Dns6CleanConfigure (&DnsModeData->DnsConfigData);
+    FreePool (ServerList);
+    gBS->RestoreTPL (OldTpl);
+    return Status;
+  }
+  
   Index =0;
   NET_LIST_FOR_EACH_SAFE (Entry, Next, &mDriverData->Dns6CacheList) {
     CacheItem = NET_LIST_USER_STRUCT (Entry, DNS6_CACHE, AllCacheLink);
     CopyMem (CacheList + Index, &CacheItem->DnsCache, sizeof 
(EFI_DNS6_CACHE_ENTRY));
     Index++;
--
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to