NetworkPkg: Fix the driver model issue in HTTP Boot driver.

The HTTP Boot driver have some UEFI driver model problems which will make the
code ASSERT when it's disconnected.
First, the driver opens the HttpSb protocol BY_CHILD without BY_DRIVER attribute.
So the driver binding stop won't be called when HTTP driver is disconnected, so
a child handle is left and made HTTP driver binding stop function goes into error.
This patch remove this unnecessary OpenProtocol and only unload the HII from when
both the IP4 and IP6 stack have been stopped completely.
The second issue is the HTTP boot driver always use the driver's image handle as
it's driver binding handle, it's not correct. HTTP Boot driver provides 2 separate
driver binding protocols from IP4 and IP6 stack, so it has 2 driver binding handle.
So this patch fix the code to use correct driver binding handle when create/open
a HTTP child handle.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
This commit is contained in:
Fu Siyuan 2016-03-14 10:43:42 +08:00
parent 6ddc2e438b
commit 7537258100
6 changed files with 29 additions and 41 deletions

View File

@ -447,6 +447,7 @@ HttpBootCreateHttpIo (
{ {
HTTP_IO_CONFIG_DATA ConfigData; HTTP_IO_CONFIG_DATA ConfigData;
EFI_STATUS Status; EFI_STATUS Status;
EFI_HANDLE ImageHandle;
ASSERT (Private != NULL); ASSERT (Private != NULL);
@ -456,14 +457,16 @@ HttpBootCreateHttpIo (
ConfigData.Config4.RequestTimeOut = HTTP_BOOT_REQUEST_TIMEOUT; ConfigData.Config4.RequestTimeOut = HTTP_BOOT_REQUEST_TIMEOUT;
IP4_COPY_ADDRESS (&ConfigData.Config4.LocalIp, &Private->StationIp.v4); IP4_COPY_ADDRESS (&ConfigData.Config4.LocalIp, &Private->StationIp.v4);
IP4_COPY_ADDRESS (&ConfigData.Config4.SubnetMask, &Private->SubnetMask.v4); IP4_COPY_ADDRESS (&ConfigData.Config4.SubnetMask, &Private->SubnetMask.v4);
ImageHandle = Private->Ip4Nic->ImageHandle;
} else { } else {
ConfigData.Config6.HttpVersion = HttpVersion11; ConfigData.Config6.HttpVersion = HttpVersion11;
ConfigData.Config6.RequestTimeOut = HTTP_BOOT_REQUEST_TIMEOUT; ConfigData.Config6.RequestTimeOut = HTTP_BOOT_REQUEST_TIMEOUT;
IP6_COPY_ADDRESS (&ConfigData.Config6.LocalIp, &Private->StationIp.v6); IP6_COPY_ADDRESS (&ConfigData.Config6.LocalIp, &Private->StationIp.v6);
ImageHandle = Private->Ip6Nic->ImageHandle;
} }
Status = HttpIoCreateIo ( Status = HttpIoCreateIo (
Private->Image, ImageHandle,
Private->Controller, Private->Controller,
Private->UsingIpv6 ? IP_VERSION_6 : IP_VERSION_4, Private->UsingIpv6 ? IP_VERSION_6 : IP_VERSION_4,
&ConfigData, &ConfigData,

View File

@ -553,7 +553,6 @@ HttpBootConfigFormInit (
EFI_STATUS Status; EFI_STATUS Status;
HTTP_BOOT_FORM_CALLBACK_INFO *CallbackInfo; HTTP_BOOT_FORM_CALLBACK_INFO *CallbackInfo;
VENDOR_DEVICE_PATH VendorDeviceNode; VENDOR_DEVICE_PATH VendorDeviceNode;
EFI_SERVICE_BINDING_PROTOCOL *HttpSb;
CHAR16 *MacString; CHAR16 *MacString;
CHAR16 *OldMenuString; CHAR16 *OldMenuString;
CHAR16 MenuString[128]; CHAR16 MenuString[128];
@ -600,20 +599,6 @@ HttpBootConfigFormInit (
&CallbackInfo->ConfigAccess, &CallbackInfo->ConfigAccess,
NULL NULL
); );
if (!EFI_ERROR (Status)) {
//
// Open the Parent Handle for the child
//
Status = gBS->OpenProtocol (
Private->Controller,
&gEfiHttpServiceBindingProtocolGuid,
(VOID **) &HttpSb,
Private->Image,
CallbackInfo->ChildHandle,
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
);
}
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto Error; goto Error;
} }
@ -636,7 +621,7 @@ HttpBootConfigFormInit (
// //
// Append MAC string in the menu help string // Append MAC string in the menu help string
// //
Status = NetLibGetMacString (Private->Controller, Private->Image, &MacString); Status = NetLibGetMacString (Private->Controller, NULL, &MacString);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
OldMenuString = HiiGetString ( OldMenuString = HiiGetString (
CallbackInfo->RegisteredHandle, CallbackInfo->RegisteredHandle,
@ -654,6 +639,7 @@ HttpBootConfigFormInit (
FreePool (MacString); FreePool (MacString);
FreePool (OldMenuString); FreePool (OldMenuString);
CallbackInfo->Initilized = TRUE;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -666,6 +652,7 @@ Error:
/** /**
Unload the configuration form, this includes: delete all the configuration Unload the configuration form, this includes: delete all the configuration
entries, uninstall the form callback protocol, and free the resources used. entries, uninstall the form callback protocol, and free the resources used.
The form will only be unload completely when both IP4 and IP6 stack are stopped.
@param[in] Private Pointer to the driver private data. @param[in] Private Pointer to the driver private data.
@ -680,18 +667,15 @@ HttpBootConfigFormUnload (
{ {
HTTP_BOOT_FORM_CALLBACK_INFO *CallbackInfo; HTTP_BOOT_FORM_CALLBACK_INFO *CallbackInfo;
if (Private->Ip4Nic != NULL || Private->Ip6Nic != NULL) {
//
// Only unload the configuration form when both IP4 and IP6 stack are stopped.
//
return EFI_SUCCESS;
}
CallbackInfo = &Private->CallbackInfo; CallbackInfo = &Private->CallbackInfo;
if (CallbackInfo->ChildHandle != NULL) { if (CallbackInfo->ChildHandle != NULL) {
//
// Close the child handle
//
gBS->CloseProtocol (
Private->Controller,
&gEfiHttpServiceBindingProtocolGuid,
Private->Image,
CallbackInfo->ChildHandle
);
// //
// Uninstall EFI_HII_CONFIG_ACCESS_PROTOCOL // Uninstall EFI_HII_CONFIG_ACCESS_PROTOCOL
// //

View File

@ -63,6 +63,7 @@ HttpBootConfigFormInit (
/** /**
Unload the configuration form, this includes: delete all the configuration Unload the configuration form, this includes: delete all the configuration
entries, uninstall the form callback protocol, and free the resources used. entries, uninstall the form callback protocol, and free the resources used.
The form will only be unload completely when both IP4 and IP6 stack are stopped.
@param[in] Private Pointer to the driver private data. @param[in] Private Pointer to the driver private data.

View File

@ -321,7 +321,7 @@ HttpBootIp4DxeDriverBindingStart (
); );
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
Private = HTTP_BOOT_PRIVATE_DATA_FROM_ID(Id); Private = HTTP_BOOT_PRIVATE_DATA_FROM_ID(Id);
} else { } else {
// //
// Initialize the private data structure. // Initialize the private data structure.
@ -332,7 +332,6 @@ HttpBootIp4DxeDriverBindingStart (
} }
Private->Signature = HTTP_BOOT_PRIVATE_DATA_SIGNATURE; Private->Signature = HTTP_BOOT_PRIVATE_DATA_SIGNATURE;
Private->Controller = ControllerHandle; Private->Controller = ControllerHandle;
Private->Image = This->ImageHandle;
InitializeListHead (&Private->CacheList); InitializeListHead (&Private->CacheList);
// //
// Get the NII interface if it exists, it's not required. // Get the NII interface if it exists, it's not required.
@ -399,8 +398,9 @@ HttpBootIp4DxeDriverBindingStart (
if (Private->Ip4Nic == NULL) { if (Private->Ip4Nic == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
Private->Ip4Nic->Private = Private; Private->Ip4Nic->Private = Private;
Private->Ip4Nic->Signature = HTTP_BOOT_VIRTUAL_NIC_SIGNATURE; Private->Ip4Nic->ImageHandle = This->DriverBindingHandle;
Private->Ip4Nic->Signature = HTTP_BOOT_VIRTUAL_NIC_SIGNATURE;
// //
// Create DHCP4 child instance. // Create DHCP4 child instance.
@ -793,7 +793,7 @@ HttpBootIp6DxeDriverBindingStart (
); );
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
Private = HTTP_BOOT_PRIVATE_DATA_FROM_ID(Id); Private = HTTP_BOOT_PRIVATE_DATA_FROM_ID(Id);
} else { } else {
// //
// Initialize the private data structure. // Initialize the private data structure.
@ -804,7 +804,6 @@ HttpBootIp6DxeDriverBindingStart (
} }
Private->Signature = HTTP_BOOT_PRIVATE_DATA_SIGNATURE; Private->Signature = HTTP_BOOT_PRIVATE_DATA_SIGNATURE;
Private->Controller = ControllerHandle; Private->Controller = ControllerHandle;
Private->Image = This->ImageHandle;
InitializeListHead (&Private->CacheList); InitializeListHead (&Private->CacheList);
// //
// Get the NII interface if it exists, it's not required. // Get the NII interface if it exists, it's not required.
@ -871,9 +870,10 @@ HttpBootIp6DxeDriverBindingStart (
if (Private->Ip6Nic == NULL) { if (Private->Ip6Nic == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
Private->Ip6Nic->Private = Private; Private->Ip6Nic->Private = Private;
Private->Ip6Nic->Signature = HTTP_BOOT_VIRTUAL_NIC_SIGNATURE; Private->Ip6Nic->ImageHandle = This->DriverBindingHandle;
Private->Ip6Nic->Signature = HTTP_BOOT_VIRTUAL_NIC_SIGNATURE;
// //
// Create Dhcp6 child and open Dhcp6 protocol // Create Dhcp6 child and open Dhcp6 protocol
Status = NetLibCreateServiceChild ( Status = NetLibCreateServiceChild (

View File

@ -102,6 +102,7 @@ typedef union {
struct _HTTP_BOOT_VIRTUAL_NIC { struct _HTTP_BOOT_VIRTUAL_NIC {
UINT32 Signature; UINT32 Signature;
EFI_HANDLE Controller; EFI_HANDLE Controller;
EFI_HANDLE ImageHandle;
EFI_LOAD_FILE_PROTOCOL LoadFile; EFI_LOAD_FILE_PROTOCOL LoadFile;
EFI_DEVICE_PATH_PROTOCOL *DevicePath; EFI_DEVICE_PATH_PROTOCOL *DevicePath;
HTTP_BOOT_PRIVATE_DATA *Private; HTTP_BOOT_PRIVATE_DATA *Private;
@ -118,7 +119,6 @@ struct _HTTP_BOOT_VIRTUAL_NIC {
struct _HTTP_BOOT_PRIVATE_DATA { struct _HTTP_BOOT_PRIVATE_DATA {
UINT32 Signature; UINT32 Signature;
EFI_HANDLE Controller; EFI_HANDLE Controller;
EFI_HANDLE Image;
HTTP_BOOT_VIRTUAL_NIC *Ip4Nic; HTTP_BOOT_VIRTUAL_NIC *Ip4Nic;
HTTP_BOOT_VIRTUAL_NIC *Ip6Nic; HTTP_BOOT_VIRTUAL_NIC *Ip6Nic;

View File

@ -372,7 +372,7 @@ HttpBootDns (
// //
Status = NetLibCreateServiceChild ( Status = NetLibCreateServiceChild (
Private->Controller, Private->Controller,
Private->Image, Private->Ip6Nic->ImageHandle,
&gEfiDns6ServiceBindingProtocolGuid, &gEfiDns6ServiceBindingProtocolGuid,
&Dns6Handle &Dns6Handle
); );
@ -384,7 +384,7 @@ HttpBootDns (
Dns6Handle, Dns6Handle,
&gEfiDns6ProtocolGuid, &gEfiDns6ProtocolGuid,
(VOID **) &Dns6, (VOID **) &Dns6,
Private->Image, Private->Ip6Nic->ImageHandle,
Private->Controller, Private->Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER EFI_OPEN_PROTOCOL_BY_DRIVER
); );
@ -474,7 +474,7 @@ Exit:
gBS->CloseProtocol ( gBS->CloseProtocol (
Dns6Handle, Dns6Handle,
&gEfiDns6ProtocolGuid, &gEfiDns6ProtocolGuid,
Private->Image, Private->Ip6Nic->ImageHandle,
Private->Controller Private->Controller
); );
} }
@ -482,7 +482,7 @@ Exit:
if (Dns6Handle != NULL) { if (Dns6Handle != NULL) {
NetLibDestroyServiceChild ( NetLibDestroyServiceChild (
Private->Controller, Private->Controller,
Private->Image, Private->Ip6Nic->ImageHandle,
&gEfiDns6ServiceBindingProtocolGuid, &gEfiDns6ServiceBindingProtocolGuid,
Dns6Handle Dns6Handle
); );