Skip to content

Commit 8b3338e

Browse files
uefi: Fix unsafe_op_in_unsafe_fn in device_path module
1 parent 49fa0b8 commit 8b3338e

File tree

1 file changed

+13
-9
lines changed
  • uefi/src/proto/device_path

1 file changed

+13
-9
lines changed

uefi/src/proto/device_path/mod.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ impl DevicePathNode {
173173
/// that lifetime.
174174
#[must_use]
175175
pub unsafe fn from_ffi_ptr<'a>(ptr: *const FfiDevicePath) -> &'a Self {
176-
let header = *ptr.cast::<DevicePathHeader>();
176+
let header = unsafe { *ptr.cast::<DevicePathHeader>() };
177177

178178
let data_len = usize::from(header.length) - size_of::<DevicePathHeader>();
179-
&*ptr_meta::from_raw_parts(ptr.cast(), data_len)
179+
unsafe { &*ptr_meta::from_raw_parts(ptr.cast(), data_len) }
180180
}
181181

182182
/// Cast to a [`FfiDevicePath`] pointer.
@@ -368,11 +368,11 @@ pub struct DevicePath {
368368

369369
impl ProtocolPointer for DevicePath {
370370
unsafe fn ptr_from_ffi(ptr: *const c_void) -> *const Self {
371-
ptr_meta::from_raw_parts(ptr.cast(), Self::size_in_bytes_from_ptr(ptr))
371+
ptr_meta::from_raw_parts(ptr.cast(), unsafe { Self::size_in_bytes_from_ptr(ptr) })
372372
}
373373

374374
unsafe fn mut_ptr_from_ffi(ptr: *mut c_void) -> *mut Self {
375-
ptr_meta::from_raw_parts_mut(ptr.cast(), Self::size_in_bytes_from_ptr(ptr))
375+
ptr_meta::from_raw_parts_mut(ptr.cast(), unsafe { Self::size_in_bytes_from_ptr(ptr) })
376376
}
377377
}
378378

@@ -384,13 +384,13 @@ impl DevicePath {
384384
let mut ptr = ptr.cast::<u8>();
385385
let mut total_size_in_bytes: usize = 0;
386386
loop {
387-
let node = DevicePathNode::from_ffi_ptr(ptr.cast::<FfiDevicePath>());
387+
let node = unsafe { DevicePathNode::from_ffi_ptr(ptr.cast::<FfiDevicePath>()) };
388388
let node_size_in_bytes = usize::from(node.length());
389389
total_size_in_bytes += node_size_in_bytes;
390390
if node.is_end_entire() {
391391
break;
392392
}
393-
ptr = ptr.add(node_size_in_bytes);
393+
ptr = unsafe { ptr.add(node_size_in_bytes) };
394394
}
395395

396396
total_size_in_bytes
@@ -434,7 +434,7 @@ impl DevicePath {
434434
/// that lifetime.
435435
#[must_use]
436436
pub unsafe fn from_ffi_ptr<'a>(ptr: *const FfiDevicePath) -> &'a Self {
437-
&*Self::ptr_from_ffi(ptr.cast::<c_void>())
437+
unsafe { &*Self::ptr_from_ffi(ptr.cast::<c_void>()) }
438438
}
439439

440440
/// Cast to a [`FfiDevicePath`] pointer.
@@ -669,11 +669,15 @@ pub struct LoadedImageDevicePath(DevicePath);
669669

670670
impl ProtocolPointer for LoadedImageDevicePath {
671671
unsafe fn ptr_from_ffi(ptr: *const c_void) -> *const Self {
672-
ptr_meta::from_raw_parts(ptr.cast(), DevicePath::size_in_bytes_from_ptr(ptr))
672+
ptr_meta::from_raw_parts(ptr.cast(), unsafe {
673+
DevicePath::size_in_bytes_from_ptr(ptr)
674+
})
673675
}
674676

675677
unsafe fn mut_ptr_from_ffi(ptr: *mut c_void) -> *mut Self {
676-
ptr_meta::from_raw_parts_mut(ptr.cast(), DevicePath::size_in_bytes_from_ptr(ptr))
678+
ptr_meta::from_raw_parts_mut(ptr.cast(), unsafe {
679+
DevicePath::size_in_bytes_from_ptr(ptr)
680+
})
677681
}
678682
}
679683

0 commit comments

Comments
 (0)