Skip to content

Commit 4390142

Browse files
committed
Fix a bug with find_protocol
1 parent 85c736b commit 4390142

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

uefi-utils/src/proto.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,13 @@ pub fn find_protocol<P: Protocol>() -> Option<ptr::NonNull<P>> {
4343
let bt = boot_services();
4444

4545
// Retrieve a handle implementing the protocol.
46-
let handle = {
47-
// Allocate space for 1 handle.
48-
let mut buffer = [ptr::null_mut(); 1];
49-
50-
let search_type = boot::SearchType::from_proto::<P>();
51-
52-
bt.locate_handle(search_type, Some(&mut buffer)).ok()
53-
.and_then(|len| if len == 1 { Some(buffer[0]) } else { None })?
54-
};
55-
56-
bt.handle_protocol::<P>(handle)
46+
// Note: using the `find_handles` function might not return _only_ compatible protocols.
47+
// We have to retrieve them all and find one that works.
48+
let handles = find_handles::<P>().ok()?;
49+
50+
handles.iter()
51+
.map(|&handle| bt.handle_protocol::<P>(handle))
52+
.filter(Option::is_some)
53+
.next()
54+
.unwrap_or(None)
5755
}

0 commit comments

Comments
 (0)