Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion uefi/src/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ pub fn allocate_pool(memory_type: MemoryType, size: usize) -> Result<NonNull<u8>
let ptr = unsafe { (bt.allocate_pool)(memory_type, size, &mut buffer) }
.to_result_with_val(|| buffer)?;

NonNull::new(ptr).ok_or(Status::OUT_OF_RESOURCES.into())
NonNull::new(ptr).ok_or_else(|| Status::OUT_OF_RESOURCES.into())
}

/// Frees memory allocated by [`allocate_pool`].
Expand Down
2 changes: 1 addition & 1 deletion uefi/src/data_types/strs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ impl PoolString {
pub unsafe fn new(text: *const Char16) -> crate::Result<Self> {
NonNull::new(text.cast_mut())
.map(|p| Self(PoolAllocation::new(p.cast())))
.ok_or(Status::OUT_OF_RESOURCES.into())
.ok_or_else(|| Status::OUT_OF_RESOURCES.into())
}
}

Expand Down
56 changes: 32 additions & 24 deletions uefi/src/fs/file_system/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ impl FileSystem {
let mut src = self
.open(src_path, UefiFileMode::Read, false)?
.into_regular_file()
.ok_or(Error::Io(IoError {
path: src_path.to_path_buf(),
context: IoErrorContext::NotAFile,
uefi_error: Status::INVALID_PARAMETER.into(),
}))?;
.ok_or_else(|| {
Error::Io(IoError {
path: src_path.to_path_buf(),
context: IoErrorContext::NotAFile,
uefi_error: Status::INVALID_PARAMETER.into(),
})
})?;

// Get the source file's size in bytes.
let src_size = {
Expand All @@ -91,11 +93,13 @@ impl FileSystem {
let mut dest = self
.open(dest_path, UefiFileMode::CreateReadWrite, false)?
.into_regular_file()
.ok_or(Error::Io(IoError {
path: dest_path.to_path_buf(),
context: IoErrorContext::OpenError,
uefi_error: Status::INVALID_PARAMETER.into(),
}))?;
.ok_or_else(|| {
Error::Io(IoError {
path: dest_path.to_path_buf(),
context: IoErrorContext::OpenError,
uefi_error: Status::INVALID_PARAMETER.into(),
})
})?;

// 1 MiB copy buffer.
let mut chunk = vec![0; 1024 * 1024];
Expand Down Expand Up @@ -198,13 +202,15 @@ impl FileSystem {
let mut file = self
.open(path, UefiFileMode::Read, false)?
.into_regular_file()
.ok_or(Error::Io(IoError {
path: path.to_path_buf(),
context: IoErrorContext::NotAFile,
// We do not have a real UEFI error here as we have a logical
// problem.
uefi_error: Status::INVALID_PARAMETER.into(),
}))?;
.ok_or_else(|| {
Error::Io(IoError {
path: path.to_path_buf(),
context: IoErrorContext::NotAFile,
// We do not have a real UEFI error here as we have a logical
// problem.
uefi_error: Status::INVALID_PARAMETER.into(),
})
})?;

let info = file.get_boxed_info::<UefiFileInfo>().map_err(|err| {
Error::Io(IoError {
Expand Down Expand Up @@ -237,13 +243,15 @@ impl FileSystem {
let dir = self
.open(path, UefiFileMode::Read, false)?
.into_directory()
.ok_or(Error::Io(IoError {
path: path.to_path_buf(),
context: IoErrorContext::NotADirectory,
// We do not have a real UEFI error here as we have a logical
// problem.
uefi_error: Status::INVALID_PARAMETER.into(),
}))?;
.ok_or_else(|| {
Error::Io(IoError {
path: path.to_path_buf(),
context: IoErrorContext::NotADirectory,
// We do not have a real UEFI error here as we have a logical
// problem.
uefi_error: Status::INVALID_PARAMETER.into(),
})
})?;
Ok(UefiDirectoryIter::new(dir))
}

Expand Down
2 changes: 1 addition & 1 deletion uefi/src/proto/ata/pass_thru.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl AtaDevice<'_> {
.to_result()?;
NonNull::new(path_ptr.cast_mut())
.map(|p| PoolDevicePathNode(PoolAllocation::new(p.cast())))
.ok_or(Status::OUT_OF_RESOURCES.into())
.ok_or_else(|| Status::OUT_OF_RESOURCES.into())
}
}

Expand Down
4 changes: 2 additions & 2 deletions uefi/src/proto/device_path/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl DevicePathFromText {
let ptr = (self.0.convert_text_to_device_node)(text_device_node.as_ptr().cast());
NonNull::new(ptr.cast_mut())
.map(|p| PoolDevicePathNode(PoolAllocation::new(p.cast())))
.ok_or(Status::OUT_OF_RESOURCES.into())
.ok_or_else(|| Status::OUT_OF_RESOURCES.into())
}
}

Expand All @@ -147,7 +147,7 @@ impl DevicePathFromText {
let ptr = (self.0.convert_text_to_device_path)(text_device_path.as_ptr().cast());
NonNull::new(ptr.cast_mut())
.map(|p| PoolDevicePath(PoolAllocation::new(p.cast())))
.ok_or(Status::OUT_OF_RESOURCES.into())
.ok_or_else(|| Status::OUT_OF_RESOURCES.into())
}
}
}
6 changes: 3 additions & 3 deletions uefi/src/proto/device_path/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl DevicePathUtilities {
(self.0.append_device_path)(path0.as_ffi_ptr().cast(), path1.as_ffi_ptr().cast());
NonNull::new(ptr.cast_mut())
.map(|p| PoolDevicePath(PoolAllocation::new(p.cast())))
.ok_or(Status::OUT_OF_RESOURCES.into())
.ok_or_else(|| Status::OUT_OF_RESOURCES.into())
}
}

Expand All @@ -71,7 +71,7 @@ impl DevicePathUtilities {
(self.0.append_device_node)(basepath.as_ffi_ptr().cast(), node.as_ffi_ptr().cast());
NonNull::new(ptr.cast_mut())
.map(|p| PoolDevicePath(PoolAllocation::new(p.cast())))
.ok_or(Status::OUT_OF_RESOURCES.into())
.ok_or_else(|| Status::OUT_OF_RESOURCES.into())
}
}

Expand All @@ -96,7 +96,7 @@ impl DevicePathUtilities {
);
NonNull::new(ptr.cast_mut())
.map(|p| PoolDevicePath(PoolAllocation::new(p.cast())))
.ok_or(Status::OUT_OF_RESOURCES.into())
.ok_or_else(|| Status::OUT_OF_RESOURCES.into())
}
}
}
2 changes: 1 addition & 1 deletion uefi/src/proto/hii/config_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<'a> Iterator for ConfigurationStringIter<'a> {
let (keyval, remainder) = self
.bfr
.split_once('&')
.unwrap_or((self.bfr, &self.bfr[0..0]));
.unwrap_or_else(|| (self.bfr, &self.bfr[0..0]));
self.bfr = remainder;
let (key, value) = keyval
.split_once('=')
Expand Down
2 changes: 1 addition & 1 deletion uefi/src/proto/nvme/pass_thru.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl NvmeNamespace<'_> {
.to_result()?;
NonNull::new(path_ptr.cast_mut())
.map(|p| PoolDevicePathNode(PoolAllocation::new(p.cast())))
.ok_or(Status::OUT_OF_RESOURCES.into())
.ok_or_else(|| Status::OUT_OF_RESOURCES.into())
}
}

Expand Down
2 changes: 1 addition & 1 deletion uefi/src/proto/scsi/pass_thru.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl ScsiDevice<'_> {
.to_result()?;
NonNull::new(path_ptr.cast_mut())
.map(|p| PoolDevicePathNode(PoolAllocation::new(p.cast())))
.ok_or(Status::OUT_OF_RESOURCES.into())
.ok_or_else(|| Status::OUT_OF_RESOURCES.into())
}
}

Expand Down
6 changes: 3 additions & 3 deletions uefi/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,12 +834,12 @@ impl TryFrom<&[u8]> for Time {
Self::UNSPECIFIED_TIMEZONE => None,
num => Some(num),
};
let daylight = Daylight::from_bits(bytes[14]).ok_or(
let daylight = Daylight::from_bits(bytes[14]).ok_or_else(|| {
TimeByteConversionError::InvalidFields(TimeError {
daylight: true,
..Default::default()
}),
)?;
})
})?;

let time_params = TimeParams {
year,
Expand Down