diff options
| author | Michael Brown | 2025-03-23 20:38:14 +0100 |
|---|---|---|
| committer | Michael Brown | 2025-03-24 14:19:26 +0100 |
| commit | 5a5e2a1dae525aecf97dffde2236b74710735c8d (patch) | |
| tree | f396e2ed8c211193272e7f9af705fe8c9321f949 /src/interface | |
| parent | [efi] Use efi_open_by_driver() for all by-driver protocol opens (diff) | |
| download | ipxe-5a5e2a1dae525aecf97dffde2236b74710735c8d.tar.gz ipxe-5a5e2a1dae525aecf97dffde2236b74710735c8d.tar.xz ipxe-5a5e2a1dae525aecf97dffde2236b74710735c8d.zip | |
[efi] Use efi_open_unsafe() for all explicitly unsafe protocol opens
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/interface')
| -rw-r--r-- | src/interface/efi/efi_bofm.c | 9 | ||||
| -rw-r--r-- | src/interface/efi/efi_console.c | 11 | ||||
| -rw-r--r-- | src/interface/efi/efi_init.c | 15 |
3 files changed, 15 insertions, 20 deletions
diff --git a/src/interface/efi/efi_bofm.c b/src/interface/efi/efi_bofm.c index 1be68bf8b..6d97ff445 100644 --- a/src/interface/efi/efi_bofm.c +++ b/src/interface/efi/efi_bofm.c @@ -241,10 +241,8 @@ static int efi_bofm_start ( struct efi_device *efidev ) { } /* Open PCI I/O protocol */ - if ( ( efirc = bs->OpenProtocol ( device, &efi_pci_io_protocol_guid, - &pci_io, efi_image_handle, device, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ - rc = -EEFI ( efirc ); + if ( ( rc = efi_open_unsafe ( device, &efi_pci_io_protocol_guid, + &pci_io ) ) != 0 ) { DBGC ( device, "EFIBOFM %s cannot open PCI device: %s\n", efi_handle_name ( device ), strerror ( rc ) ); goto err_open; @@ -326,8 +324,7 @@ static int efi_bofm_start ( struct efi_device *efidev ) { err_set_status: err_locate_bofm: - bs->CloseProtocol ( device, &efi_pci_io_protocol_guid, - efi_image_handle, device ); + efi_close_unsafe ( device, &efi_pci_io_protocol_guid ); err_open: err_info: return rc; diff --git a/src/interface/efi/efi_console.c b/src/interface/efi/efi_console.c index 04bbd9e0c..41c4dcf2c 100644 --- a/src/interface/efi/efi_console.c +++ b/src/interface/efi/efi_console.c @@ -415,13 +415,11 @@ struct console_driver efi_console __console_driver = { * */ static void efi_console_init ( void ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_CONSOLE_CONTROL_SCREEN_MODE mode; union { void *interface; EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *wtf; } u; - EFI_STATUS efirc; int rc; /* 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 * applications. Don't ask. */ - if ( ( efirc = bs->OpenProtocol ( efi_systab->ConsoleInHandle, - &efi_simple_text_input_ex_protocol_guid, - &u.interface, efi_image_handle, - efi_systab->ConsoleInHandle, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) == 0 ) { + if ( ( rc = efi_open_unsafe ( efi_systab->ConsoleInHandle, + &efi_simple_text_input_ex_protocol_guid, + &u.interface ) ) == 0 ) { efi_conin_ex = u.wtf; DBG ( "EFI using SimpleTextInputEx\n" ); } else { - rc = -EEFI ( efirc ); DBG ( "EFI has no SimpleTextInputEx: %s\n", strerror ( rc ) ); } } diff --git a/src/interface/efi/efi_init.c b/src/interface/efi/efi_init.c index d3c5042d7..a45ee66a4 100644 --- a/src/interface/efi/efi_init.c +++ b/src/interface/efi/efi_init.c @@ -241,14 +241,17 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle, } } - /* Get loaded image protocol */ - if ( ( efirc = bs->OpenProtocol ( image_handle, - &efi_loaded_image_protocol_guid, - &loaded_image, image_handle, NULL, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) { - rc = -EEFI ( efirc ); + /* Get loaded image protocol + * + * We assume that our loaded image protocol will not be + * uninstalled while our image code is still running. + */ + 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", strerror ( rc ) ); + efirc = EFIRC ( rc ); goto err_no_loaded_image; } efi_loaded_image = loaded_image; |
