public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ye, Ting" <ting.ye@intel.com>
To: "Fu, Siyuan" <siyuan.fu@intel.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: "Wang, Fan" <fan.wang@intel.com>, "Wu, Jiaxin" <jiaxin.wu@intel.com>
Subject: Re: [Patch] MdeModulePkg/Ip4Dxe: return error on memory allocate failure instead of ASSERT.
Date: Wed, 13 Dec 2017 03:06:12 +0000	[thread overview]
Message-ID: <BC0C045B0E2A584CA4575E779FA2C12A1A982336@SHSMSX103.ccr.corp.intel.com> (raw)
In-Reply-To: <20171213024321.9664-1-siyuan.fu@intel.com>

Reviewed-by: Ye Ting <ting.ye@intel.com> 

-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Fu Siyuan
Sent: Wednesday, December 13, 2017 10:43 AM
To: edk2-devel@lists.01.org
Cc: Ye, Ting <ting.ye@intel.com>; Wang, Fan <fan.wang@intel.com>; Wu, Jiaxin <jiaxin.wu@intel.com>
Subject: [edk2] [Patch] MdeModulePkg/Ip4Dxe: return error on memory allocate failure instead of ASSERT.

This patch updates the IP4 driver to use error status code instead of ASSERT if failed to allocate memory buffer.

Cc: Ye Ting <ting.ye@intel.com>
Cc: Wu Jiaxin <jiaxin.wu@intel.com>
Cc: Wang Fan <fan.wang@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu Siyuan <siyuan.fu@intel.com>
---
 MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

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

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


      reply	other threads:[~2017-12-13  3:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-13  2:43 [Patch] MdeModulePkg/Ip4Dxe: return error on memory allocate failure instead of ASSERT Fu Siyuan
2017-12-13  3:06 ` Ye, Ting [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BC0C045B0E2A584CA4575E779FA2C12A1A982336@SHSMSX103.ccr.corp.intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox