@@ -36,12 +36,16 @@ pub fn initialize_driver_binding(image_handle: efi::Handle) -> Result<(), efi::S
3636 driver_binding_handle,
3737 } ) ) ;
3838
39- let status = ( boot_services. install_protocol_interface ) (
40- core:: ptr:: addr_of_mut!( driver_binding_handle) ,
41- & driver_binding:: PROTOCOL_GUID as * const efi:: Guid as * mut efi:: Guid ,
42- efi:: NATIVE_INTERFACE ,
43- driver_binding_ptr as * mut c_void ,
44- ) ;
39+ // SAFETY: `boot_services` references a valid Boot Services table and the arguments below are valid
40+ // for installing the driver binding protocol.
41+ let status = unsafe {
42+ ( boot_services. install_protocol_interface ) (
43+ core:: ptr:: addr_of_mut!( driver_binding_handle) ,
44+ & driver_binding:: PROTOCOL_GUID as * const efi:: Guid as * mut efi:: Guid ,
45+ efi:: NATIVE_INTERFACE ,
46+ driver_binding_ptr as * mut c_void ,
47+ )
48+ } ;
4549
4650 if status. is_error ( ) {
4751 drop ( unsafe { Box :: from_raw ( driver_binding_ptr) } ) ;
@@ -77,14 +81,18 @@ extern "efiapi" fn uefi_hid_driver_binding_supported(
7781
7882 // Check to see if this controller is supported by attempting to open HidIo on it.
7983 let mut hid_io_ptr: * mut hid_io:: protocol:: Protocol = core:: ptr:: null_mut ( ) ;
80- let status = ( boot_services. open_protocol ) (
81- controller,
82- & hid_io:: protocol:: GUID as * const efi:: Guid as * mut efi:: Guid ,
83- core:: ptr:: addr_of_mut!( hid_io_ptr) as * mut * mut c_void ,
84- driver_binding. driver_binding_handle ,
85- controller,
86- efi:: OPEN_PROTOCOL_BY_DRIVER ,
87- ) ;
84+ // SAFETY: `boot_services` references a valid Boot Services table and the arguments below are valid
85+ // for opening the HidIo protocol on `controller`.
86+ let status = unsafe {
87+ ( boot_services. open_protocol ) (
88+ controller,
89+ & hid_io:: protocol:: GUID as * const efi:: Guid as * mut efi:: Guid ,
90+ core:: ptr:: addr_of_mut!( hid_io_ptr) as * mut * mut c_void ,
91+ driver_binding. driver_binding_handle ,
92+ controller,
93+ efi:: OPEN_PROTOCOL_BY_DRIVER ,
94+ )
95+ } ;
8896
8997 // if HidIo could not be opened then it is either in use or not present.
9098 if status. is_error ( ) {
@@ -93,12 +101,16 @@ extern "efiapi" fn uefi_hid_driver_binding_supported(
93101
94102 // HidIo is available, so this controller is supported. Further checking that requires actual device interaction is
95103 // done in uefi_hid_driver_binding_start. close the protocol used for the supported test and exit with success.
96- let status = ( boot_services. close_protocol ) (
97- controller,
98- & hid_io:: protocol:: GUID as * const efi:: Guid as * mut efi:: Guid ,
99- driver_binding. driver_binding_handle ,
100- controller,
101- ) ;
104+ // SAFETY: `boot_services` references a valid Boot Services table and the arguments below match the
105+ // protocol opened above.
106+ let status = unsafe {
107+ ( boot_services. close_protocol ) (
108+ controller,
109+ & hid_io:: protocol:: GUID as * const efi:: Guid as * mut efi:: Guid ,
110+ driver_binding. driver_binding_handle ,
111+ controller,
112+ )
113+ } ;
102114 if status. is_error ( ) {
103115 debugln ! ( DEBUG_ERROR , "Unexpected error from CloseProtocol: {:?}" , status) ;
104116 //message, but no further action to handle.
0 commit comments