diff --git a/uefi/src/boot.rs b/uefi/src/boot.rs index 280da5c13..234e4b3bd 100644 --- a/uefi/src/boot.rs +++ b/uefi/src/boot.rs @@ -238,7 +238,7 @@ pub fn allocate_pool(memory_type: MemoryType, size: usize) -> Result 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`]. diff --git a/uefi/src/data_types/strs.rs b/uefi/src/data_types/strs.rs index a9b6b9489..74205c785 100644 --- a/uefi/src/data_types/strs.rs +++ b/uefi/src/data_types/strs.rs @@ -745,7 +745,7 @@ impl PoolString { pub unsafe fn new(text: *const Char16) -> crate::Result { 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()) } } diff --git a/uefi/src/fs/file_system/fs.rs b/uefi/src/fs/file_system/fs.rs index 4e89b0d65..0b2c872a8 100644 --- a/uefi/src/fs/file_system/fs.rs +++ b/uefi/src/fs/file_system/fs.rs @@ -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 = { @@ -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]; @@ -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::().map_err(|err| { Error::Io(IoError { @@ -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)) } diff --git a/uefi/src/proto/ata/pass_thru.rs b/uefi/src/proto/ata/pass_thru.rs index 43447b02b..76adcef17 100644 --- a/uefi/src/proto/ata/pass_thru.rs +++ b/uefi/src/proto/ata/pass_thru.rs @@ -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()) } } diff --git a/uefi/src/proto/device_path/text.rs b/uefi/src/proto/device_path/text.rs index 358dbba00..5c00959e0 100644 --- a/uefi/src/proto/device_path/text.rs +++ b/uefi/src/proto/device_path/text.rs @@ -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()) } } @@ -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()) } } } diff --git a/uefi/src/proto/device_path/util.rs b/uefi/src/proto/device_path/util.rs index 7314f1a83..bc1dbab74 100644 --- a/uefi/src/proto/device_path/util.rs +++ b/uefi/src/proto/device_path/util.rs @@ -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()) } } @@ -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()) } } @@ -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()) } } } diff --git a/uefi/src/proto/hii/config_str.rs b/uefi/src/proto/hii/config_str.rs index 6852c30b0..ef13209d2 100644 --- a/uefi/src/proto/hii/config_str.rs +++ b/uefi/src/proto/hii/config_str.rs @@ -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('=') diff --git a/uefi/src/proto/nvme/pass_thru.rs b/uefi/src/proto/nvme/pass_thru.rs index fe12c0b26..415ddd9b5 100644 --- a/uefi/src/proto/nvme/pass_thru.rs +++ b/uefi/src/proto/nvme/pass_thru.rs @@ -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()) } } diff --git a/uefi/src/proto/scsi/pass_thru.rs b/uefi/src/proto/scsi/pass_thru.rs index fbc6b5a30..26d50c687 100644 --- a/uefi/src/proto/scsi/pass_thru.rs +++ b/uefi/src/proto/scsi/pass_thru.rs @@ -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()) } } diff --git a/uefi/src/runtime.rs b/uefi/src/runtime.rs index e1be79d1c..1ad1a7940 100644 --- a/uefi/src/runtime.rs +++ b/uefi/src/runtime.rs @@ -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,