Skip to content

Commit 075c47c

Browse files
committed
uefi: remove unnecessary unsafe for Event::from_ptr
There is nothing unsafe here. `NonNull` properly covers null pointers by returning `None`.
1 parent 585b4dd commit 075c47c

File tree

6 files changed

+11
-13
lines changed

6 files changed

+11
-13
lines changed

uefi/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
- Changed ordering of `proto::pci::PciIoAddress` to (bus -> dev -> fun -> reg -> ext_reg).
1212
- Return request with status as error data object for `proto::ata::pass_thru::AtaDevice`.
1313
- **Breaking:** `proto::network::snp::SimpleNetwork::wait_for_packet` now
14-
returns `Option<Event>` instead of `&Event`.
14+
returns `Option<Event>` instead of `&Event`. It has also been renamed to
15+
`wait_for_packet`.
1516

1617
# uefi - v0.36.1 (2025-11-05)
1718

uefi/src/boot.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ pub unsafe fn create_event(
424424
unsafe { (bt.create_event)(event_ty, notify_tpl, notify_fn, notify_ctx, &mut event) }
425425
.to_result_with_val(
426426
// OK to unwrap: event is non-null for Status::SUCCESS.
427-
|| unsafe { Event::from_ptr(event) }.unwrap(),
427+
|| Event::from_ptr(event).unwrap(),
428428
)
429429
}
430430

@@ -502,7 +502,7 @@ pub unsafe fn create_event_ex(
502502
}
503503
.to_result_with_val(
504504
// OK to unwrap: event is non-null for Status::SUCCESS.
505-
|| unsafe { Event::from_ptr(event) }.unwrap(),
505+
|| Event::from_ptr(event).unwrap(),
506506
)
507507
}
508508

uefi/src/data_types/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,9 @@ impl Event {
8282
Self(self.0)
8383
}
8484

85-
/// Create an `Event` from a raw pointer.
86-
///
87-
/// # Safety
88-
///
89-
/// The caller must ensure that the pointer is valid.
90-
pub unsafe fn from_ptr(ptr: *mut c_void) -> Option<Self> {
85+
/// Create an [`Event`] from a raw pointer. Returns [`None`] if the pointer
86+
/// null.
87+
pub fn from_ptr(ptr: *mut c_void) -> Option<Self> {
9188
NonNull::new(ptr).map(Self)
9289
}
9390

uefi/src/proto/console/pointer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl Pointer {
5555
/// [`boot::wait_for_event`]: crate::boot::wait_for_event
5656
#[must_use]
5757
pub fn wait_for_input_event(&self) -> Option<Event> {
58-
unsafe { Event::from_ptr(self.0.wait_for_input) }
58+
Event::from_ptr(self.0.wait_for_input)
5959
}
6060

6161
/// Returns a reference to the pointer device information.

uefi/src/proto/console/text/input.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl Input {
8686
/// [`boot::wait_for_event`]: crate::boot::wait_for_event
8787
#[must_use]
8888
pub fn wait_for_key_event(&self) -> Option<Event> {
89-
unsafe { Event::from_ptr(self.0.wait_for_key) }
89+
Event::from_ptr(self.0.wait_for_key)
9090
}
9191
}
9292

uefi/src/proto/network/snp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ impl SimpleNetwork {
270270
/// On QEMU, this event seems to never fire; it is suggested to verify that your implementation
271271
/// of UEFI properly implements this event before using it.
272272
#[must_use]
273-
pub fn wait_for_packet(&self) -> Option<Event> {
274-
unsafe { Event::from_ptr(self.0.wait_for_packet) }
273+
pub fn wait_for_packet_event(&self) -> Option<Event> {
274+
Event::from_ptr(self.0.wait_for_packet)
275275
}
276276

277277
/// Returns a reference to the Simple Network mode.

0 commit comments

Comments
 (0)