Skip to content

Commit 2fdff0f

Browse files
uefi: Return an option from LoadedImage::device
It's not guaranteed that the `device_handle` will be non-null, so return an option.
1 parent 3e643f1 commit 2fdff0f

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Changed
66
- `Input::wait_for_key_event` now returns an `Option<Event>`, and is no longer `const`.
7+
- `LoadedImage::device` now returns an `Option<Handle>`.
78

89
## uefi-macros - [Unreleased]
910

uefi-test-runner/src/proto/device_path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn test(image: Handle, bt: &BootServices) {
1616
.expect("Failed to open LoadedImage protocol");
1717

1818
let device_path = bt
19-
.open_protocol_exclusive::<DevicePath>(loaded_image.device())
19+
.open_protocol_exclusive::<DevicePath>(loaded_image.device().unwrap())
2020
.expect("Failed to open DevicePath protocol");
2121

2222
let device_path_to_text = bt

uefi/src/proto/loaded_image.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct LoadedImage {
1818
system_table: *const c_void,
1919

2020
// Source location of the image
21-
device_handle: Handle,
21+
device_handle: Option<Handle>,
2222
file_path: *const FfiDevicePath,
2323
_reserved: *const c_void,
2424

@@ -52,7 +52,7 @@ pub enum LoadOptionsError {
5252
impl LoadedImage {
5353
/// Returns a handle to the storage device on which the image is located.
5454
#[must_use]
55-
pub const fn device(&self) -> Handle {
55+
pub const fn device(&self) -> Option<Handle> {
5656
self.device_handle
5757
}
5858

uefi/src/table/boot.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::Revision;
44
use crate::data_types::{Align, PhysicalAddress};
55
use crate::proto::device_path::DevicePath;
66
use crate::proto::{Protocol, ProtocolPointer};
7-
use crate::{Char16, Event, Guid, Handle, Result, Status, StatusExt};
7+
use crate::{Char16, Error, Event, Guid, Handle, Result, Status, StatusExt};
88
use core::cell::UnsafeCell;
99
use core::ffi::c_void;
1010
use core::fmt::{Debug, Formatter};
@@ -1398,7 +1398,10 @@ impl BootServices {
13981398
pub fn get_image_file_system(&self, image_handle: Handle) -> Result<FileSystem> {
13991399
let loaded_image = self.open_protocol_exclusive::<LoadedImage>(image_handle)?;
14001400

1401-
let device_path = self.open_protocol_exclusive::<DevicePath>(loaded_image.device())?;
1401+
let device_handle = loaded_image
1402+
.device()
1403+
.ok_or(Error::new(Status::UNSUPPORTED, ()))?;
1404+
let device_path = self.open_protocol_exclusive::<DevicePath>(device_handle)?;
14021405

14031406
let device_handle = self.locate_device_path::<SimpleFileSystem>(&mut &*device_path)?;
14041407

0 commit comments

Comments
 (0)