@@ -8,7 +8,13 @@ use bootloader_api::{info::FrameBufferInfo, BootloaderConfig};
8
8
use bootloader_x86_64_common:: {
9
9
legacy_memory_region:: LegacyFrameAllocator , Kernel , RawFrameBufferInfo , SystemInfo ,
10
10
} ;
11
- use core:: { cell:: UnsafeCell , fmt:: Write , mem, ptr, slice} ;
11
+ use core:: {
12
+ cell:: UnsafeCell ,
13
+ fmt:: Write ,
14
+ mem,
15
+ ops:: { Deref , DerefMut } ,
16
+ ptr, slice,
17
+ } ;
12
18
use uefi:: {
13
19
prelude:: { entry, Boot , Handle , Status , SystemTable } ,
14
20
proto:: {
@@ -179,7 +185,7 @@ fn open_device_path_protocol(
179
185
return None ;
180
186
}
181
187
let loaded_image = loaded_image. unwrap ( ) ;
182
- let loaded_image = unsafe { & * loaded_image. interface . get ( ) } ;
188
+ let loaded_image = loaded_image. deref ( ) ;
183
189
184
190
let device_handle = loaded_image. device ( ) ;
185
191
@@ -205,13 +211,8 @@ fn locate_and_open_protocol<P: ProtocolPointer>(
205
211
st : & SystemTable < Boot > ,
206
212
) -> Option < ScopedProtocol < P > > {
207
213
let this = st. boot_services ( ) ;
208
- let device_path = open_device_path_protocol ( image, st) ;
209
- if device_path. is_none ( ) {
210
- log:: error!( "Unable to open device path protocol from boot services" ) ;
211
- return None ;
212
- }
213
- let device_path = device_path. unwrap ( ) ;
214
- let mut device_path = unsafe { & * device_path. interface . get ( ) } ;
214
+ let mut device_path = open_device_path_protocol ( image, st) ?;
215
+ let mut device_path = device_path. deref ( ) ;
215
216
216
217
let fs_handle = this. locate_device_path :: < P > ( & mut device_path) ;
217
218
if fs_handle. is_err ( ) {
@@ -244,13 +245,8 @@ fn load_file_from_disk(
244
245
image : Handle ,
245
246
st : & SystemTable < Boot > ,
246
247
) -> Option < & ' static mut [ u8 ] > {
247
- let file_system_raw = locate_and_open_protocol :: < SimpleFileSystem > ( image, st) ;
248
-
249
- if file_system_raw. is_none ( ) {
250
- return None ;
251
- }
252
- let file_system_raw = file_system_raw. unwrap ( ) ;
253
- let file_system = unsafe { & mut * file_system_raw. interface . get ( ) } ;
248
+ let mut file_system_raw = locate_and_open_protocol :: < SimpleFileSystem > ( image, st) ?;
249
+ let file_system = file_system_raw. deref_mut ( ) ;
254
250
255
251
let mut root = file_system. open_volume ( ) . unwrap ( ) ;
256
252
let mut buf = [ 0u16 ; 256 ] ;
@@ -296,13 +292,8 @@ fn load_file_from_tftp_boot_server(
296
292
image : Handle ,
297
293
st : & SystemTable < Boot > ,
298
294
) -> Option < & ' static mut [ u8 ] > {
299
- let base_code_raw = locate_and_open_protocol :: < BaseCode > ( image, st) ;
300
- if base_code_raw. is_none ( ) {
301
- // The previous code will log errors along the way, we do not need to.
302
- return None ;
303
- }
304
- let base_code_raw = base_code_raw. unwrap ( ) ;
305
- let base_code = unsafe { & mut * base_code_raw. interface . get ( ) } ;
295
+ let mut base_code_raw = locate_and_open_protocol :: < BaseCode > ( image, st) ?;
296
+ let base_code = base_code_raw. deref_mut ( ) ;
306
297
307
298
// Find the TFTP boot server.
308
299
let mode = base_code. mode ( ) ;
0 commit comments