[efi] Use efi_open_by_driver() for all by-driver protocol opens

Signed-off-by: Michael Brown <mcb30@ipxe.org>
pull/34/merge
Michael Brown 2025-03-23 18:06:15 +00:00
parent 4561a03766
commit 9dd30f11f7
7 changed files with 43 additions and 102 deletions

View File

@ -367,7 +367,6 @@ static struct net_device_operations mnpnet_operations = {
* @ret rc Return status code
*/
int mnpnet_start ( struct efi_device *efidev ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_HANDLE device = efidev->device;
EFI_GUID *binding = &efi_managed_network_service_binding_protocol_guid;
EFI_SIMPLE_NETWORK_MODE mode;
@ -408,13 +407,9 @@ int mnpnet_start ( struct efi_device *efidev ) {
}
/* Open MNP protocol */
if ( ( efirc = bs->OpenProtocol ( efidev->child,
&efi_managed_network_protocol_guid,
&u.interface, efi_image_handle,
efidev->child,
( EFI_OPEN_PROTOCOL_BY_DRIVER |
EFI_OPEN_PROTOCOL_EXCLUSIVE )))!=0){
rc = -EEFI ( efirc );
if ( ( rc = efi_open_by_driver ( efidev->child,
&efi_managed_network_protocol_guid,
&u.interface ) ) != 0 ) {
DBGC ( mnp, "MNP %s could not open MNP protocol: %s\n",
efi_handle_name ( device ), strerror ( rc ) );
goto err_open;
@ -464,8 +459,8 @@ int mnpnet_start ( struct efi_device *efidev ) {
err_ll_addr_len:
err_hw_addr_len:
err_mode:
bs->CloseProtocol ( efidev->child, &efi_managed_network_protocol_guid,
efi_image_handle, efidev->child );
efi_close_by_driver ( efidev->child,
&efi_managed_network_protocol_guid );
err_open:
efi_service_del ( device, binding, efidev->child );
err_service:
@ -482,7 +477,6 @@ int mnpnet_start ( struct efi_device *efidev ) {
* @v efidev EFI device
*/
void mnpnet_stop ( struct efi_device *efidev ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_GUID *binding = &efi_managed_network_service_binding_protocol_guid;
struct net_device *netdev = efidev_get_drvdata ( efidev );
struct mnp_nic *mnp = netdev->priv;
@ -491,8 +485,8 @@ void mnpnet_stop ( struct efi_device *efidev ) {
unregister_netdev ( netdev );
/* Close MNP protocol */
bs->CloseProtocol ( efidev->child, &efi_managed_network_protocol_guid,
efi_image_handle, efidev->child );
efi_close_by_driver ( efidev->child,
&efi_managed_network_protocol_guid );
/* Remove MNP child (unless whole system shutdown is in progress) */
if ( ! efi_shutdown_in_progress )

View File

@ -1270,12 +1270,10 @@ static struct net_device_operations nii_operations = {
* @ret rc Return status code
*/
int nii_start ( struct efi_device *efidev ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_HANDLE device = efidev->device;
struct net_device *netdev;
struct nii_nic *nii;
void *interface;
EFI_STATUS efirc;
int rc;
/* Allocate and initialise structure */
@ -1300,11 +1298,8 @@ int nii_start ( struct efi_device *efidev ) {
netdev->dev = &nii->dev;
/* Open NII protocol */
if ( ( efirc = bs->OpenProtocol ( device, &efi_nii31_protocol_guid,
&interface, efi_image_handle, device,
( EFI_OPEN_PROTOCOL_BY_DRIVER |
EFI_OPEN_PROTOCOL_EXCLUSIVE )))!=0){
rc = -EEFI ( efirc );
if ( ( rc = efi_open_by_driver ( device, &efi_nii31_protocol_guid,
&interface ) ) != 0 ) {
DBGC ( nii, "NII %s cannot open NII protocol: %s\n",
nii->dev.name, strerror ( rc ) );
DBGC_EFI_OPENERS ( device, device, &efi_nii31_protocol_guid );
@ -1373,8 +1368,7 @@ int nii_start ( struct efi_device *efidev ) {
err_pci_open:
err_hw_undi:
err_no_undi:
bs->CloseProtocol ( device, &efi_nii31_protocol_guid,
efi_image_handle, device );
efi_close_by_driver ( device, &efi_nii31_protocol_guid );
err_open_protocol:
list_del ( &nii->dev.siblings );
netdev_nullify ( netdev );
@ -1389,7 +1383,6 @@ int nii_start ( struct efi_device *efidev ) {
* @v efidev EFI device
*/
void nii_stop ( struct efi_device *efidev ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct net_device *netdev = efidev_get_drvdata ( efidev );
struct nii_nic *nii = netdev->priv;
EFI_HANDLE device = efidev->device;
@ -1404,8 +1397,7 @@ void nii_stop ( struct efi_device *efidev ) {
nii_pci_close ( nii );
/* Close NII protocol */
bs->CloseProtocol ( device, &efi_nii31_protocol_guid,
efi_image_handle, device );
efi_close_by_driver ( device, &efi_nii31_protocol_guid );
/* Free network device */
list_del ( &nii->dev.siblings );

View File

@ -539,7 +539,6 @@ int snpnet_supported ( EFI_HANDLE device, EFI_GUID *protocol ) {
* @ret rc Return status code
*/
int snpnet_start ( struct efi_device *efidev ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_HANDLE device = efidev->device;
EFI_SIMPLE_NETWORK_MODE *mode;
struct net_device *netdev;
@ -549,12 +548,9 @@ int snpnet_start ( struct efi_device *efidev ) {
int rc;
/* Open SNP protocol */
if ( ( efirc = bs->OpenProtocol ( device,
&efi_simple_network_protocol_guid,
&interface, efi_image_handle, device,
( EFI_OPEN_PROTOCOL_BY_DRIVER |
EFI_OPEN_PROTOCOL_EXCLUSIVE )))!=0){
rc = -EEFI ( efirc );
if ( ( rc = efi_open_by_driver ( device,
&efi_simple_network_protocol_guid,
&interface ) ) != 0 ) {
DBGC ( device, "SNP %s cannot open SNP protocol: %s\n",
efi_handle_name ( device ), strerror ( rc ) );
DBGC_EFI_OPENERS ( device, device,
@ -644,8 +640,7 @@ int snpnet_start ( struct efi_device *efidev ) {
netdev_nullify ( netdev );
netdev_put ( netdev );
err_alloc:
bs->CloseProtocol ( device, &efi_simple_network_protocol_guid,
efi_image_handle, device );
efi_close_by_driver ( device, &efi_simple_network_protocol_guid );
err_open_protocol:
return rc;
}
@ -656,7 +651,6 @@ int snpnet_start ( struct efi_device *efidev ) {
* @v efidev EFI device
*/
void snpnet_stop ( struct efi_device *efidev ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct net_device *netdev = efidev_get_drvdata ( efidev );
struct snp_nic *snp = netdev->priv;
EFI_HANDLE device = efidev->device;
@ -681,6 +675,5 @@ void snpnet_stop ( struct efi_device *efidev ) {
netdev_put ( netdev );
/* Close SNP protocol */
bs->CloseProtocol ( device, &efi_simple_network_protocol_guid,
efi_image_handle, device );
efi_close_by_driver ( device, &efi_simple_network_protocol_guid );
}

View File

@ -229,13 +229,9 @@ static int usbio_open ( struct usbio_device *usbio, unsigned int interface ) {
}
/* Open USB I/O protocol on this handle */
if ( ( efirc = bs->OpenProtocol ( intf->handle,
&efi_usb_io_protocol_guid,
&u.interface, efi_image_handle,
intf->handle,
( EFI_OPEN_PROTOCOL_BY_DRIVER |
EFI_OPEN_PROTOCOL_EXCLUSIVE )))!=0){
rc = -EEFI ( efirc );
if ( ( rc = efi_open_by_driver ( intf->handle,
&efi_usb_io_protocol_guid,
&u.interface ) ) != 0 ) {
DBGC ( usbio, "USBIO %s cannot open ",
efi_handle_name ( handle ) );
DBGC ( usbio, "%s: %s\n",
@ -259,7 +255,6 @@ static int usbio_open ( struct usbio_device *usbio, unsigned int interface ) {
* @v interface Interface number
*/
static void usbio_close ( struct usbio_device *usbio, unsigned int interface ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct usbio_interface *intf = &usbio->interface[interface];
/* Sanity checks */
@ -274,8 +269,7 @@ static void usbio_close ( struct usbio_device *usbio, unsigned int interface ) {
return;
/* Close USB I/O protocol */
bs->CloseProtocol ( intf->handle, &efi_usb_io_protocol_guid,
efi_image_handle, intf->handle );
efi_close_by_driver ( intf->handle, &efi_usb_io_protocol_guid );
}
/******************************************************************************
@ -1608,7 +1602,6 @@ static int usbio_interfaces ( struct usbio_device *usbio ) {
* @ret rc Return status code
*/
static int usbio_start ( struct efi_device *efidev ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_HANDLE handle = efidev->device;
struct usbio_device *usbio;
struct usb_port *port;
@ -1616,7 +1609,6 @@ static int usbio_start ( struct efi_device *efidev ) {
void *interface;
EFI_USB_IO_PROTOCOL *io;
} u;
EFI_STATUS efirc;
int rc;
/* Allocate and initialise structure */
@ -1630,12 +1622,8 @@ static int usbio_start ( struct efi_device *efidev ) {
INIT_LIST_HEAD ( &usbio->endpoints );
/* Open USB I/O protocol */
if ( ( efirc = bs->OpenProtocol ( handle, &efi_usb_io_protocol_guid,
&u.interface, efi_image_handle,
handle,
( EFI_OPEN_PROTOCOL_BY_DRIVER |
EFI_OPEN_PROTOCOL_EXCLUSIVE )))!=0){
rc = -EEFI ( efirc );
if ( ( rc = efi_open_by_driver ( handle, &efi_usb_io_protocol_guid,
&u.interface ) ) != 0 ) {
DBGC ( usbio, "USBIO %s cannot open USB I/O protocol: %s\n",
efi_handle_name ( handle ), strerror ( rc ) );
DBGC_EFI_OPENERS ( usbio, handle, &efi_usb_io_protocol_guid );
@ -1692,8 +1680,7 @@ static int usbio_start ( struct efi_device *efidev ) {
free ( usbio->config );
err_config:
list_del ( &usbio->dev.siblings );
bs->CloseProtocol ( handle, &efi_usb_io_protocol_guid,
efi_image_handle, handle );
efi_close_by_driver ( handle, &efi_usb_io_protocol_guid );
err_open_usbio:
free ( usbio );
err_alloc:
@ -1706,7 +1693,6 @@ static int usbio_start ( struct efi_device *efidev ) {
* @v efidev EFI device
*/
static void usbio_stop ( struct efi_device *efidev ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_HANDLE handle = efidev->device;
struct usbio_device *usbio = efidev_get_drvdata ( efidev );
@ -1716,8 +1702,7 @@ static void usbio_stop ( struct efi_device *efidev ) {
free ( usbio->path );
free ( usbio->config );
list_del ( &usbio->dev.siblings );
bs->CloseProtocol ( handle, &efi_usb_io_protocol_guid,
efi_image_handle, handle );
efi_close_by_driver ( handle, &efi_usb_io_protocol_guid );
free ( usbio );
}

View File

@ -1169,11 +1169,8 @@ int efi_file_install ( EFI_HANDLE handle ) {
* of calls to our DRIVER_STOP method when starting the EFI
* shell. I have no idea why this is.
*/
if ( ( efirc = bs->OpenProtocol ( handle, &efi_disk_io_protocol_guid,
&diskio.interface, efi_image_handle,
handle,
EFI_OPEN_PROTOCOL_BY_DRIVER ) ) != 0){
rc = -EEFI ( efirc );
if ( ( rc = efi_open_by_driver ( handle, &efi_disk_io_protocol_guid,
&diskio.interface ) ) != 0 ) {
DBGC ( handle, "Could not open disk I/O protocol: %s\n",
strerror ( rc ) );
DBGC_EFI_OPENERS ( handle, handle, &efi_disk_io_protocol_guid );
@ -1199,8 +1196,7 @@ int efi_file_install ( EFI_HANDLE handle ) {
efi_file_path_uninstall ( &efi_file_initrd );
err_initrd_install:
err_initrd_claim:
bs->CloseProtocol ( handle, &efi_disk_io_protocol_guid,
efi_image_handle, handle );
efi_close_by_driver ( handle, &efi_disk_io_protocol_guid );
err_open:
bs->UninstallMultipleProtocolInterfaces (
handle,
@ -1228,8 +1224,7 @@ void efi_file_uninstall ( EFI_HANDLE handle ) {
efi_file_path_uninstall ( &efi_file_initrd );
/* Close our own disk I/O protocol */
bs->CloseProtocol ( handle, &efi_disk_io_protocol_guid,
efi_image_handle, handle );
efi_close_by_driver ( handle, &efi_disk_io_protocol_guid );
/* We must install the file system protocol first, since
* otherwise the EDK2 code will attempt to helpfully uninstall

View File

@ -902,11 +902,9 @@ static int efipci_supported ( EFI_HANDLE device ) {
* @ret rc Return status code
*/
static int efipci_start ( struct efi_device *efidev ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_HANDLE device = efidev->device;
struct efi_pci_device *efipci;
void *pci_io;
EFI_STATUS efirc;
int rc;
/* Allocate PCI device */
@ -920,12 +918,9 @@ static int efipci_start ( struct efi_device *efidev ) {
if ( ( rc = efipci_info ( device, efipci ) ) != 0 )
goto err_info;
/* Open PCI device */
if ( ( efirc = bs->OpenProtocol ( device, &efi_pci_io_protocol_guid,
&pci_io, efi_image_handle, device,
( EFI_OPEN_PROTOCOL_BY_DRIVER |
EFI_OPEN_PROTOCOL_EXCLUSIVE )))!=0){
rc = -EEFI_PCI ( efirc );
/* Open PCI I/O protocol */
if ( ( rc = efi_open_by_driver ( device, &efi_pci_io_protocol_guid,
&pci_io ) ) != 0 ) {
DBGC ( device, "EFIPCI %s could not open PCI device: %s\n",
efi_handle_name ( device ), strerror ( rc ) );
DBGC_EFI_OPENERS ( device, device, &efi_pci_io_protocol_guid );
@ -960,8 +955,7 @@ static int efipci_start ( struct efi_device *efidev ) {
err_probe:
list_del ( &efipci->pci.dev.siblings );
err_find_driver:
bs->CloseProtocol ( device, &efi_pci_io_protocol_guid,
efi_image_handle, device );
efi_close_by_driver ( device, &efi_pci_io_protocol_guid );
err_open:
err_info:
free ( efipci );
@ -976,15 +970,13 @@ static int efipci_start ( struct efi_device *efidev ) {
*/
static void efipci_stop ( struct efi_device *efidev ) {
struct efi_pci_device *efipci = efidev_get_drvdata ( efidev );
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_HANDLE device = efidev->device;
pci_remove ( &efipci->pci );
list_del ( &efipci->pci.dev.siblings );
assert ( efipci->pci.dma.mapped == 0 );
assert ( efipci->pci.dma.allocated == 0 );
bs->CloseProtocol ( device, &efi_pci_io_protocol_guid,
efi_image_handle, device );
efi_close_by_driver ( device, &efi_pci_io_protocol_guid );
free ( efipci );
}

View File

@ -1916,22 +1916,16 @@ static int efi_snp_probe ( struct net_device *netdev, void *priv __unused ) {
* instances to prevent SnpDxe from attempting to bind to
* them.
*/
if ( ( efirc = bs->OpenProtocol ( snpdev->handle,
&efi_nii_protocol_guid, &interface,
efi_image_handle, snpdev->handle,
( EFI_OPEN_PROTOCOL_BY_DRIVER |
EFI_OPEN_PROTOCOL_EXCLUSIVE )))!=0){
rc = -EEFI ( efirc );
if ( ( rc = efi_open_by_driver ( snpdev->handle,
&efi_nii_protocol_guid,
&interface ) ) != 0 ) {
DBGC ( snpdev, "SNPDEV %p could not open NII protocol: %s\n",
snpdev, strerror ( rc ) );
goto err_open_nii;
}
if ( ( efirc = bs->OpenProtocol ( snpdev->handle,
&efi_nii31_protocol_guid, &interface,
efi_image_handle, snpdev->handle,
( EFI_OPEN_PROTOCOL_BY_DRIVER |
EFI_OPEN_PROTOCOL_EXCLUSIVE )))!=0){
rc = -EEFI ( efirc );
if ( ( rc = efi_open_by_driver ( snpdev->handle,
&efi_nii31_protocol_guid,
&interface ) ) != 0 ) {
DBGC ( snpdev, "SNPDEV %p could not open NII31 protocol: %s\n",
snpdev, strerror ( rc ) );
goto err_open_nii31;
@ -1967,11 +1961,9 @@ static int efi_snp_probe ( struct net_device *netdev, void *priv __unused ) {
leak |= efi_snp_hii_uninstall ( snpdev );
efi_child_del ( efidev->device, snpdev->handle );
err_efi_child_add:
bs->CloseProtocol ( snpdev->handle, &efi_nii31_protocol_guid,
efi_image_handle, snpdev->handle );
efi_close_by_driver ( snpdev->handle, &efi_nii31_protocol_guid );
err_open_nii31:
bs->CloseProtocol ( snpdev->handle, &efi_nii_protocol_guid,
efi_image_handle, snpdev->handle );
efi_close_by_driver ( snpdev->handle, &efi_nii_protocol_guid );
err_open_nii:
if ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
snpdev->handle,
@ -2060,10 +2052,8 @@ static void efi_snp_remove ( struct net_device *netdev, void *priv __unused ) {
if ( snpdev->package_list )
leak |= efi_snp_hii_uninstall ( snpdev );
efi_child_del ( snpdev->efidev->device, snpdev->handle );
bs->CloseProtocol ( snpdev->handle, &efi_nii_protocol_guid,
efi_image_handle, snpdev->handle );
bs->CloseProtocol ( snpdev->handle, &efi_nii31_protocol_guid,
efi_image_handle, snpdev->handle );
efi_close_by_driver ( snpdev->handle, &efi_nii_protocol_guid );
efi_close_by_driver ( snpdev->handle, &efi_nii31_protocol_guid );
if ( ( ! efi_shutdown_in_progress ) &&
( ( efirc = bs->UninstallMultipleProtocolInterfaces (
snpdev->handle,