Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions uefi/src/proto/media/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ impl BlockIO2 {
/// * `media_id` - The media ID that the read request is for.
/// * `lba` - The starting logical block address to read from on the device.
/// * `token` - Transaction token for asynchronous read.
/// * `len` - Buffer size.
/// * `buffer` - The target buffer of the read operation
///
/// # Safety
Expand All @@ -256,12 +255,20 @@ impl BlockIO2 {
media_id: u32,
lba: Lba,
token: Option<NonNull<BlockIO2Token>>,
len: usize,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @Virv12 FYI. Unfortunately, I missed this in the review.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this change, using a reference introduces a lifetime, implying we are going to use the buffer only until the lifetime is alive, which is wrong.

There has been a similar discussion on DiskIO2.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for pointing that out to me, I wasn't aware of this anymore!

buffer: *mut u8,
buffer: &mut [u8],
) -> Result {
let token = opt_nonnull_to_ptr(token);
unsafe { (self.0.read_blocks_ex)(&self.0, media_id, lba, token.cast(), len, buffer.cast()) }
.to_result()
unsafe {
(self.0.read_blocks_ex)(
&self.0,
media_id,
lba,
token.cast(),
buffer.len(),
buffer.as_mut_ptr().cast(),
)
}
.to_result()
}

/// Writes a specified number of blocks to the device.
Expand All @@ -270,7 +277,6 @@ impl BlockIO2 {
/// * `media_id` - The media ID that the write request is for.
/// * `lba` - The starting logical block address to be written.
/// * `token` - Transaction token for asynchronous write.
/// * `len` - Buffer size.
/// * `buffer` - Buffer to be written from.
///
/// # Safety
Expand All @@ -290,12 +296,18 @@ impl BlockIO2 {
media_id: u32,
lba: Lba,
token: Option<NonNull<BlockIO2Token>>,
len: usize,
buffer: *const u8,
buffer: &[u8],
) -> Result {
let token = opt_nonnull_to_ptr(token);
unsafe {
(self.0.write_blocks_ex)(&mut self.0, media_id, lba, token.cast(), len, buffer.cast())
(self.0.write_blocks_ex)(
&mut self.0,
media_id,
lba,
token.cast(),
buffer.len(),
buffer.as_ptr().cast(),
)
}
.to_result()
}
Expand Down