diff options
Diffstat (limited to 'MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Driver.c')
-rw-r--r-- | MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Driver.c | 88 |
1 files changed, 61 insertions, 27 deletions
diff --git a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Driver.c b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Driver.c index 8a773d9461..20758d38cf 100644 --- a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Driver.c +++ b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Driver.c @@ -212,7 +212,6 @@ Dhcp4CreateService ( DhcpSb->Signature = DHCP_SERVICE_SIGNATURE;
DhcpSb->ServiceState = DHCP_UNCONFIGED;
- DhcpSb->InDestroy = FALSE;
DhcpSb->Controller = Controller;
DhcpSb->Image = ImageHandle;
InitializeListHead (&DhcpSb->Children);
@@ -354,6 +353,35 @@ ON_ERROR: return Status;
}
+/**
+ Callback function which provided by user to remove one node in NetDestroyLinkList process.
+
+ @param[in] Entry The entry to be removed.
+ @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
+
+ @retval EFI_SUCCESS The entry has been removed successfully.
+ @retval Others Fail to remove the entry.
+
+**/
+EFI_STATUS
+Dhcp4DestroyChildEntry (
+ IN LIST_ENTRY *Entry,
+ IN VOID *Context
+)
+{
+ DHCP_PROTOCOL *Instance;
+ EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
+
+ if (Entry == NULL || Context == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Instance = NET_LIST_USER_STRUCT_S (Entry, DHCP_PROTOCOL, Link, DHCP_PROTOCOL_SIGNATURE);
+ ServiceBinding = (EFI_SERVICE_BINDING_PROTOCOL *) Context;
+
+ return ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle);
+}
+
/**
Stop this driver on ControllerHandle. This service is called by the
@@ -384,10 +412,10 @@ Dhcp4DriverBindingStop ( {
EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
DHCP_SERVICE *DhcpSb;
- DHCP_PROTOCOL *Instance;
EFI_HANDLE NicHandle;
EFI_STATUS Status;
- EFI_TPL OldTpl;
+ LIST_ENTRY *List;
+ UINTN ListLength;
//
// DHCP driver opens UDP child, So, the ControllerHandle is the
@@ -396,7 +424,7 @@ Dhcp4DriverBindingStop ( NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiUdp4ProtocolGuid);
if (NicHandle == NULL) {
- return EFI_DEVICE_ERROR;
+ return EFI_SUCCESS;
}
Status = gBS->OpenProtocol (
@@ -413,16 +441,30 @@ Dhcp4DriverBindingStop ( }
DhcpSb = DHCP_SERVICE_FROM_THIS (ServiceBinding);
-
- if (DhcpSb->InDestroy) {
- return EFI_SUCCESS;
+ if (!IsListEmpty (&DhcpSb->Children)) {
+ //
+ // Destroy all the children instances before destory the service.
+ //
+ List = &DhcpSb->Children;
+ Status = NetDestroyLinkList (
+ List,
+ Dhcp4DestroyChildEntry,
+ ServiceBinding,
+ &ListLength
+ );
+ if (EFI_ERROR (Status) || ListLength != 0) {
+ Status = EFI_DEVICE_ERROR;
+ }
}
- OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
-
- if (NumberOfChildren == 0) {
+ if (NumberOfChildren == 0 && !IsListEmpty (&DhcpSb->Children)) {
+ Status = EFI_DEVICE_ERROR;
+ }
- DhcpSb->InDestroy = TRUE;
+ if (NumberOfChildren == 0 && IsListEmpty (&DhcpSb->Children)) {
+ //
+ // Destroy the service itself if no child instance left.
+ //
DhcpSb->ServiceState = DHCP_DESTROY;
gBS->UninstallProtocolInterface (
@@ -433,24 +475,15 @@ Dhcp4DriverBindingStop ( Dhcp4CloseService (DhcpSb);
- FreePool (DhcpSb);
- } else {
- //
- // Don't use NET_LIST_FOR_EACH_SAFE here, Dhcp4ServiceBindingDestroyChild
- // may cause other child to be deleted.
- //
- while (!IsListEmpty (&DhcpSb->Children)) {
- Instance = NET_LIST_HEAD (&DhcpSb->Children, DHCP_PROTOCOL, Link);
- ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle);
- }
-
- if (DhcpSb->NumChildren != 0) {
- Status = EFI_DEVICE_ERROR;
+ if (gDhcpControllerNameTable != NULL) {
+ FreeUnicodeStringTable (gDhcpControllerNameTable);
+ gDhcpControllerNameTable = NULL;
}
+ FreePool (DhcpSb);
+
+ Status = EFI_SUCCESS;
}
- gBS->RestoreTPL (OldTpl);
-
return Status;
}
@@ -663,12 +696,13 @@ Dhcp4ServiceBindingDestroyChild ( //
// Uninstall the DHCP4 protocol first to enable a top down destruction.
//
+ gBS->RestoreTPL (OldTpl);
Status = gBS->UninstallProtocolInterface (
ChildHandle,
&gEfiDhcp4ProtocolGuid,
Dhcp
);
-
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
if (EFI_ERROR (Status)) {
Instance->InDestroy = FALSE;
|