From nobody Mon Dec 23 18:49:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1515045746254850.4701162393111; Wed, 3 Jan 2018 22:02:26 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9F01A222D1553; Wed, 3 Jan 2018 21:57:18 -0800 (PST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 620EB222D154F for ; Wed, 3 Jan 2018 21:57:16 -0800 (PST) Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Jan 2018 22:02:20 -0800 Received: from fanwang2-hp.ccr.corp.intel.com ([10.239.9.33]) by orsmga006.jf.intel.com with ESMTP; 03 Jan 2018 22:02:18 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.88; helo=mga01.intel.com; envelope-from=fan.wang@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,505,1508828400"; d="scan'208";a="8336134" From: fanwang2 To: edk2-devel@lists.01.org Date: Thu, 4 Jan 2018 14:02:15 +0800 Message-Id: <1515045735-9004-1-git-send-email-fan.wang@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 Subject: [edk2] [Patch] MdeModulePkg/DxeUdpIoLib: Did some code enhancement for UdpIoLib X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ye Ting , Wang Fan , Fu Siyuan , Jiaxin Wu MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Wang Fan * Added some ASSERT descriptions for library APIs. * Added "Optional" option for Context parameter in UdpIoCancelDgrams(). * Added function return status check for UdpIoFreeIo(). Cc: Ye Ting Cc: Fu Siyuan Cc: Jiaxin Wu Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wang Fan Reviewed-by: Fu Siyuan --- MdeModulePkg/Include/Library/UdpIoLib.h | 16 ++++- MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.c | 90 ++++++++++++++++++----= ---- 2 files changed, 78 insertions(+), 28 deletions(-) diff --git a/MdeModulePkg/Include/Library/UdpIoLib.h b/MdeModulePkg/Include= /Library/UdpIoLib.h index e0b44ce..86a11a9 100644 --- a/MdeModulePkg/Include/Library/UdpIoLib.h +++ b/MdeModulePkg/Include/Library/UdpIoLib.h @@ -195,11 +195,13 @@ BOOLEAN IN VOID *Context ); =20 /** Cancel all the sent datagram that pass the selection criteria of ToCance= l. + If ToCancel is NULL, all the datagrams are cancelled. + If Udp version is not Udp4 or Udp6, then ASSERT(). =20 @param[in] UdpIo The UDP_IO to cancel packet. @param[in] IoStatus The IoStatus to return to the packet o= wners. @param[in] ToCancel The select funtion to test whether to = cancel this packet or not. @@ -210,17 +212,20 @@ VOID EFIAPI UdpIoCancelDgrams ( IN UDP_IO *UdpIo, IN EFI_STATUS IoStatus, IN UDP_IO_TO_CANCEL ToCancel, OPTIONAL - IN VOID *Context + IN VOID *Context OPTIONAL ); =20 /** Creates a UDP_IO to access the UDP service. It creates and configures a UDP child. =20 + If Configure is NULL, then ASSERT(). + If Udp version is not Udp4 or Udp6, then ASSERT(). + It locates the UDP service binding prototype on the Controller parameter uses the UDP service binding prototype to create a UDP child (also known= as a UDP instance) configures the UDP child by calling Configure function p= rototype. Any failures in creating or configuring the UDP child return NULL for fa= ilure. =20 @@ -245,15 +250,18 @@ UdpIoCreateIo ( ); =20 /** Free the UDP_IO and all its related resources. =20 + If Udp version is not Udp4 or Udp6, then ASSERT(). + The function cancels all sent datagrams and receive requests. =20 @param[in] UdpIo The UDP_IO to free. =20 @retval EFI_SUCCESS The UDP_IO is freed. + @retval Others Failed to free UDP_IO. =20 **/ EFI_STATUS EFIAPI UdpIoFreeIo ( @@ -262,10 +270,12 @@ UdpIoFreeIo ( =20 /** Cleans up the UDP_IO without freeing it. Call this function if you intend to later re-use the UDP_IO. =20 + If Udp version is not Udp4 or Udp6, then ASSERT(). + This function releases all transmitted datagrams and receive requests an= d configures NULL for the UDP instance. =20 @param[in] UdpIo The UDP_IO to clean up. =20 **/ @@ -276,10 +286,12 @@ UdpIoCleanIo ( ); =20 /** Send a packet through the UDP_IO. =20 + If Udp version is not Udp4 or Udp6, then ASSERT(). + The packet will be wrapped in UDP_TX_TOKEN. Function Callback will be ca= lled when the packet is sent. The optional parameter EndPoint overrides the d= efault address pair if specified. =20 @param[in] UdpIo The UDP_IO to send the packet through. @@ -322,10 +334,12 @@ UdpIoCancelSentDatagram ( ); =20 /** Issue a receive request to the UDP_IO. =20 + If Udp version is not Udp4 or Udp6, then ASSERT(). + This function is called when upper-layer needs packet from UDP for proce= ssing. Only one receive request is acceptable at a time. Therefore, one common = usage model is to invoke this function inside its Callback function when the former pac= ket is processed. =20 diff --git a/MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.c b/MdeModulePkg/= Library/DxeUdpIoLib/DxeUdpIoLib.c index 4861095..e2d3466 100644 --- a/MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.c +++ b/MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.c @@ -408,10 +408,13 @@ UdpIoCreateRxToken ( } =20 /** Wrap a transmit request into a new created UDP_TX_TOKEN. =20 + If Packet is NULL, then ASSERT(). + If Udp version is not Udp4 or Udp6, then ASSERT(). + @param[in] UdpIo The UdpIo to send packet to. @param[in] Packet The user's packet. @param[in] EndPoint The local and remote access point. @param[in] Gateway The overrided next hop. @param[in] CallBack The function to call when transmission= completed. @@ -578,10 +581,13 @@ UdpIoCreateTxToken ( =20 /** Creates a UDP_IO to access the UDP service. It creates and configures a UDP child. =20 + If Configure is NULL, then ASSERT(). + If Udp version is not Udp4 or Udp6, then ASSERT(). + It locates the UDP service binding prototype on the Controller parameter uses the UDP service binding prototype to create a UDP child (also known= as a UDP instance) configures the UDP child by calling Configure function p= rototype. Any failures in creating or configuring the UDP child return NULL for fa= ilure. =20 @@ -747,11 +753,13 @@ FREE_MEM: return NULL; } =20 /** Cancel all the sent datagram that pass the selection criteria of ToCance= l. + If ToCancel is NULL, all the datagrams are cancelled. + If Udp version is not Udp4 or Udp6, then ASSERT(). =20 @param[in] UdpIo The UDP_IO to cancel packet. @param[in] IoStatus The IoStatus to return to the packet o= wners. @param[in] ToCancel The select funtion to test whether to = cancel this packet or not. @@ -762,11 +770,11 @@ VOID EFIAPI UdpIoCancelDgrams ( IN UDP_IO *UdpIo, IN EFI_STATUS IoStatus, IN UDP_IO_TO_CANCEL ToCancel, OPTIONAL - IN VOID *Context + IN VOID *Context OPTIONAL ) { LIST_ENTRY *Entry; LIST_ENTRY *Next; UDP_TX_TOKEN *TxToken; @@ -789,23 +797,27 @@ UdpIoCancelDgrams ( } =20 /** Free the UDP_IO and all its related resources. =20 + If Udp version is not Udp4 or Udp6, then ASSERT(). + The function will cancel all sent datagram and receive request. =20 @param[in] UdpIo The UDP_IO to free. =20 @retval EFI_SUCCESS The UDP_IO is freed. + @retval Others Failed to free UDP_IO. =20 **/ EFI_STATUS EFIAPI UdpIoFreeIo ( IN UDP_IO *UdpIo ) { + EFI_STATUS Status; UDP_RX_TOKEN *RxToken; =20 ASSERT ((UdpIo->UdpVersion =3D=3D UDP_IO_UDP4_VERSION) || (UdpIo->UdpVersion =3D=3D UDP_IO_UDP6_VERSION)); =20 @@ -820,53 +832,71 @@ UdpIoFreeIo ( UdpIoCancelDgrams (UdpIo, EFI_ABORTED, NULL, NULL); =20 if (UdpIo->UdpVersion =3D=3D UDP_IO_UDP4_VERSION) { =20 if ((RxToken =3D UdpIo->RecvRequest) !=3D NULL) { - UdpIo->Protocol.Udp4->Cancel (UdpIo->Protocol.Udp4, &RxToken->Token.= Udp4); + Status =3D UdpIo->Protocol.Udp4->Cancel (UdpIo->Protocol.Udp4, &RxTo= ken->Token.Udp4); + if (EFI_ERROR (Status)) { + return Status; + } } =20 // // Close then destroy the Udp4 child // - gBS->CloseProtocol ( - UdpIo->UdpHandle, - &gEfiUdp4ProtocolGuid, - UdpIo->Image, - UdpIo->Controller - ); + Status =3D gBS->CloseProtocol ( + UdpIo->UdpHandle, + &gEfiUdp4ProtocolGuid, + UdpIo->Image, + UdpIo->Controller + ); + if (EFI_ERROR (Status)) { + return Status; + } =20 - NetLibDestroyServiceChild ( - UdpIo->Controller, - UdpIo->Image, - &gEfiUdp4ServiceBindingProtocolGuid, - UdpIo->UdpHandle - ); + Status =3D NetLibDestroyServiceChild ( + UdpIo->Controller, + UdpIo->Image, + &gEfiUdp4ServiceBindingProtocolGuid, + UdpIo->UdpHandle + ); + if (EFI_ERROR (Status)) { + return Status; + } =20 } else { =20 if ((RxToken =3D UdpIo->RecvRequest) !=3D NULL) { - UdpIo->Protocol.Udp6->Cancel (UdpIo->Protocol.Udp6, &RxToken->Token.= Udp6); + Status =3D UdpIo->Protocol.Udp6->Cancel (UdpIo->Protocol.Udp6, &RxTo= ken->Token.Udp6); + if (EFI_ERROR (Status)) { + return Status; + } } =20 // // Close then destroy the Udp6 child // - gBS->CloseProtocol ( - UdpIo->UdpHandle, - &gEfiUdp6ProtocolGuid, - UdpIo->Image, - UdpIo->Controller - ); + Status =3D gBS->CloseProtocol ( + UdpIo->UdpHandle, + &gEfiUdp6ProtocolGuid, + UdpIo->Image, + UdpIo->Controller + ); + if (EFI_ERROR (Status)) { + return Status; + } =20 - NetLibDestroyServiceChild ( - UdpIo->Controller, - UdpIo->Image, - &gEfiUdp6ServiceBindingProtocolGuid, - UdpIo->UdpHandle - ); + Status =3D NetLibDestroyServiceChild ( + UdpIo->Controller, + UdpIo->Image, + &gEfiUdp6ServiceBindingProtocolGuid, + UdpIo->UdpHandle + ); + if (EFI_ERROR (Status)) { + return Status; } + } =20 if (!IsListEmpty(&UdpIo->Link)) { RemoveEntryList (&UdpIo->Link); } =20 @@ -877,10 +907,12 @@ UdpIoFreeIo ( =20 /** Clean up the UDP_IO without freeing it. The function is called when user wants to re-use the UDP_IO later. =20 + If Udp version is not Udp4 or Udp6, then ASSERT(). + It will release all the transmitted datagrams and receive request. It wi= ll also configure NULL for the UDP instance. =20 @param[in] UdpIo The UDP_IO to clean up. =20 @@ -918,10 +950,12 @@ UdpIoCleanIo ( } =20 /** Send a packet through the UDP_IO. =20 + If Udp version is not Udp4 or Udp6, then ASSERT(). + The packet will be wrapped in UDP_TX_TOKEN. Function Callback will be ca= lled when the packet is sent. The optional parameter EndPoint overrides the d= efault address pair if specified. =20 @param[in] UdpIo The UDP_IO to send the packet through. @@ -1028,10 +1062,12 @@ UdpIoCancelSentDatagram ( } =20 /** Issue a receive request to the UDP_IO. =20 + If Udp version is not Udp4 or Udp6, then ASSERT(). + This function is called when upper-layer needs packet from UDP for proce= ssing. Only one receive request is acceptable at a time so a common usage model= is to invoke this function inside its Callback function when the former pac= ket is processed. =20 --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel