mirror of
https://github.com/ipxe/ipxe
synced 2025-12-08 18:30:28 +03:00
[efi] Use efi_open_unsafe() for all explicitly unsafe protocol opens
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -230,12 +230,14 @@ static int nii_pci_open ( struct nii_nic *nii ) {
|
|||||||
}
|
}
|
||||||
nii->pci_device = pci_device;
|
nii->pci_device = pci_device;
|
||||||
|
|
||||||
/* Open PCI I/O protocol */
|
/* Open PCI I/O protocol
|
||||||
if ( ( efirc = bs->OpenProtocol ( pci_device, &efi_pci_io_protocol_guid,
|
*
|
||||||
&pci_io.interface, efi_image_handle,
|
* We cannot open this safely as a by-driver open, since doing
|
||||||
device,
|
* so would disconnect the underlying NII driver. We must
|
||||||
EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
|
* therefore use an unsafe open.
|
||||||
rc = -EEFI ( efirc );
|
*/
|
||||||
|
if ( ( rc = efi_open_unsafe ( pci_device, &efi_pci_io_protocol_guid,
|
||||||
|
&pci_io.interface ) ) != 0 ) {
|
||||||
DBGC ( nii, "NII %s could not open PCI I/O protocol: %s\n",
|
DBGC ( nii, "NII %s could not open PCI I/O protocol: %s\n",
|
||||||
nii->dev.name, strerror ( rc ) );
|
nii->dev.name, strerror ( rc ) );
|
||||||
goto err_open;
|
goto err_open;
|
||||||
@@ -280,8 +282,7 @@ static int nii_pci_open ( struct nii_nic *nii ) {
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_get_bar_attributes:
|
err_get_bar_attributes:
|
||||||
bs->CloseProtocol ( pci_device, &efi_pci_io_protocol_guid,
|
efi_close_unsafe ( pci_device, &efi_pci_io_protocol_guid );
|
||||||
efi_image_handle, device );
|
|
||||||
err_open:
|
err_open:
|
||||||
err_locate:
|
err_locate:
|
||||||
return rc;
|
return rc;
|
||||||
@@ -294,7 +295,6 @@ static int nii_pci_open ( struct nii_nic *nii ) {
|
|||||||
* @ret rc Return status code
|
* @ret rc Return status code
|
||||||
*/
|
*/
|
||||||
static void nii_pci_close ( struct nii_nic *nii ) {
|
static void nii_pci_close ( struct nii_nic *nii ) {
|
||||||
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
|
|
||||||
struct nii_mapping *map;
|
struct nii_mapping *map;
|
||||||
struct nii_mapping *tmp;
|
struct nii_mapping *tmp;
|
||||||
|
|
||||||
@@ -308,8 +308,7 @@ static void nii_pci_close ( struct nii_nic *nii ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Close protocols */
|
/* Close protocols */
|
||||||
bs->CloseProtocol ( nii->pci_device, &efi_pci_io_protocol_guid,
|
efi_close_unsafe ( nii->pci_device, &efi_pci_io_protocol_guid );
|
||||||
efi_image_handle, nii->efidev->device );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -241,10 +241,8 @@ static int efi_bofm_start ( struct efi_device *efidev ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Open PCI I/O protocol */
|
/* Open PCI I/O protocol */
|
||||||
if ( ( efirc = bs->OpenProtocol ( device, &efi_pci_io_protocol_guid,
|
if ( ( rc = efi_open_unsafe ( device, &efi_pci_io_protocol_guid,
|
||||||
&pci_io, efi_image_handle, device,
|
&pci_io ) ) != 0 ) {
|
||||||
EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
|
|
||||||
rc = -EEFI ( efirc );
|
|
||||||
DBGC ( device, "EFIBOFM %s cannot open PCI device: %s\n",
|
DBGC ( device, "EFIBOFM %s cannot open PCI device: %s\n",
|
||||||
efi_handle_name ( device ), strerror ( rc ) );
|
efi_handle_name ( device ), strerror ( rc ) );
|
||||||
goto err_open;
|
goto err_open;
|
||||||
@@ -326,8 +324,7 @@ static int efi_bofm_start ( struct efi_device *efidev ) {
|
|||||||
|
|
||||||
err_set_status:
|
err_set_status:
|
||||||
err_locate_bofm:
|
err_locate_bofm:
|
||||||
bs->CloseProtocol ( device, &efi_pci_io_protocol_guid,
|
efi_close_unsafe ( device, &efi_pci_io_protocol_guid );
|
||||||
efi_image_handle, device );
|
|
||||||
err_open:
|
err_open:
|
||||||
err_info:
|
err_info:
|
||||||
return rc;
|
return rc;
|
||||||
|
|||||||
@@ -415,13 +415,11 @@ struct console_driver efi_console __console_driver = {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static void efi_console_init ( void ) {
|
static void efi_console_init ( void ) {
|
||||||
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
|
|
||||||
EFI_CONSOLE_CONTROL_SCREEN_MODE mode;
|
EFI_CONSOLE_CONTROL_SCREEN_MODE mode;
|
||||||
union {
|
union {
|
||||||
void *interface;
|
void *interface;
|
||||||
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *wtf;
|
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *wtf;
|
||||||
} u;
|
} u;
|
||||||
EFI_STATUS efirc;
|
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* On some older EFI 1.10 implementations, we must use the
|
/* On some older EFI 1.10 implementations, we must use the
|
||||||
@@ -441,15 +439,12 @@ static void efi_console_init ( void ) {
|
|||||||
* apparently the expected behaviour for all UEFI
|
* apparently the expected behaviour for all UEFI
|
||||||
* applications. Don't ask.
|
* applications. Don't ask.
|
||||||
*/
|
*/
|
||||||
if ( ( efirc = bs->OpenProtocol ( efi_systab->ConsoleInHandle,
|
if ( ( rc = efi_open_unsafe ( efi_systab->ConsoleInHandle,
|
||||||
&efi_simple_text_input_ex_protocol_guid,
|
&efi_simple_text_input_ex_protocol_guid,
|
||||||
&u.interface, efi_image_handle,
|
&u.interface ) ) == 0 ) {
|
||||||
efi_systab->ConsoleInHandle,
|
|
||||||
EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) == 0 ) {
|
|
||||||
efi_conin_ex = u.wtf;
|
efi_conin_ex = u.wtf;
|
||||||
DBG ( "EFI using SimpleTextInputEx\n" );
|
DBG ( "EFI using SimpleTextInputEx\n" );
|
||||||
} else {
|
} else {
|
||||||
rc = -EEFI ( efirc );
|
|
||||||
DBG ( "EFI has no SimpleTextInputEx: %s\n", strerror ( rc ) );
|
DBG ( "EFI has no SimpleTextInputEx: %s\n", strerror ( rc ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -241,14 +241,17 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get loaded image protocol */
|
/* Get loaded image protocol
|
||||||
if ( ( efirc = bs->OpenProtocol ( image_handle,
|
*
|
||||||
&efi_loaded_image_protocol_guid,
|
* We assume that our loaded image protocol will not be
|
||||||
&loaded_image, image_handle, NULL,
|
* uninstalled while our image code is still running.
|
||||||
EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
|
*/
|
||||||
rc = -EEFI ( efirc );
|
if ( ( rc = efi_open_unsafe ( image_handle,
|
||||||
|
&efi_loaded_image_protocol_guid,
|
||||||
|
&loaded_image ) ) != 0 ) {
|
||||||
DBGC ( systab, "EFI could not get loaded image protocol: %s",
|
DBGC ( systab, "EFI could not get loaded image protocol: %s",
|
||||||
strerror ( rc ) );
|
strerror ( rc ) );
|
||||||
|
efirc = EFIRC ( rc );
|
||||||
goto err_no_loaded_image;
|
goto err_no_loaded_image;
|
||||||
}
|
}
|
||||||
efi_loaded_image = loaded_image;
|
efi_loaded_image = loaded_image;
|
||||||
|
|||||||
Reference in New Issue
Block a user