Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d807908

Browse files
committed
uefi: use or_else whenever there is a function call
1 parent 5d50811 commit d807908

File tree

10 files changed

+46
-38
lines changed

10 files changed

+46
-38
lines changed

‎uefi/src/boot.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ pub fn allocate_pool(memory_type: MemoryType, size: usize) -> Result<NonNull<u8>
238238
let ptr = unsafe { (bt.allocate_pool)(memory_type, size, &mut buffer) }
239239
.to_result_with_val(|| buffer)?;
240240

241-
NonNull::new(ptr).ok_or(Status::OUT_OF_RESOURCES.into())
241+
NonNull::new(ptr).ok_or_else(|| Status::OUT_OF_RESOURCES.into())
242242
}
243243

244244
/// Frees memory allocated by [`allocate_pool`].

‎uefi/src/data_types/strs.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ impl PoolString {
745745
pub unsafe fn new(text: *const Char16) -> crate::Result<Self> {
746746
NonNull::new(text.cast_mut())
747747
.map(|p| Self(PoolAllocation::new(p.cast())))
748-
.ok_or(Status::OUT_OF_RESOURCES.into())
748+
.ok_or_else(|| Status::OUT_OF_RESOURCES.into())
749749
}
750750
}
751751

‎uefi/src/fs/file_system/fs.rs‎

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,13 @@ impl FileSystem {
6363
let mut src = self
6464
.open(src_path, UefiFileMode::Read, false)?
6565
.into_regular_file()
66-
.ok_or(Error::Io(IoError {
67-
path: src_path.to_path_buf(),
68-
context: IoErrorContext::NotAFile,
69-
uefi_error: Status::INVALID_PARAMETER.into(),
70-
}))?;
66+
.ok_or_else(|| {
67+
Error::Io(IoError {
68+
path: src_path.to_path_buf(),
69+
context: IoErrorContext::NotAFile,
70+
uefi_error: Status::INVALID_PARAMETER.into(),
71+
})
72+
})?;
7173

7274
// Get the source file's size in bytes.
7375
let src_size = {
@@ -91,11 +93,13 @@ impl FileSystem {
9193
let mut dest = self
9294
.open(dest_path, UefiFileMode::CreateReadWrite, false)?
9395
.into_regular_file()
94-
.ok_or(Error::Io(IoError {
95-
path: dest_path.to_path_buf(),
96-
context: IoErrorContext::OpenError,
97-
uefi_error: Status::INVALID_PARAMETER.into(),
98-
}))?;
96+
.ok_or_else(|| {
97+
Error::Io(IoError {
98+
path: dest_path.to_path_buf(),
99+
context: IoErrorContext::OpenError,
100+
uefi_error: Status::INVALID_PARAMETER.into(),
101+
})
102+
})?;
99103

100104
// 1 MiB copy buffer.
101105
let mut chunk = vec![0; 1024 * 1024];
@@ -198,13 +202,15 @@ impl FileSystem {
198202
let mut file = self
199203
.open(path, UefiFileMode::Read, false)?
200204
.into_regular_file()
201-
.ok_or(Error::Io(IoError {
202-
path: path.to_path_buf(),
203-
context: IoErrorContext::NotAFile,
204-
// We do not have a real UEFI error here as we have a logical
205-
// problem.
206-
uefi_error: Status::INVALID_PARAMETER.into(),
207-
}))?;
205+
.ok_or_else(|| {
206+
Error::Io(IoError {
207+
path: path.to_path_buf(),
208+
context: IoErrorContext::NotAFile,
209+
// We do not have a real UEFI error here as we have a logical
210+
// problem.
211+
uefi_error: Status::INVALID_PARAMETER.into(),
212+
})
213+
})?;
208214

209215
let info = file.get_boxed_info::<UefiFileInfo>().map_err(|err| {
210216
Error::Io(IoError {
@@ -237,13 +243,15 @@ impl FileSystem {
237243
let dir = self
238244
.open(path, UefiFileMode::Read, false)?
239245
.into_directory()
240-
.ok_or(Error::Io(IoError {
241-
path: path.to_path_buf(),
242-
context: IoErrorContext::NotADirectory,
243-
// We do not have a real UEFI error here as we have a logical
244-
// problem.
245-
uefi_error: Status::INVALID_PARAMETER.into(),
246-
}))?;
246+
.ok_or_else(|| {
247+
Error::Io(IoError {
248+
path: path.to_path_buf(),
249+
context: IoErrorContext::NotADirectory,
250+
// We do not have a real UEFI error here as we have a logical
251+
// problem.
252+
uefi_error: Status::INVALID_PARAMETER.into(),
253+
})
254+
})?;
247255
Ok(UefiDirectoryIter::new(dir))
248256
}
249257

‎uefi/src/proto/ata/pass_thru.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl AtaDevice<'_> {
156156
.to_result()?;
157157
NonNull::new(path_ptr.cast_mut())
158158
.map(|p| PoolDevicePathNode(PoolAllocation::new(p.cast())))
159-
.ok_or(Status::OUT_OF_RESOURCES.into())
159+
.ok_or_else(|| Status::OUT_OF_RESOURCES.into())
160160
}
161161
}
162162

‎uefi/src/proto/device_path/text.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl DevicePathFromText {
130130
let ptr = (self.0.convert_text_to_device_node)(text_device_node.as_ptr().cast());
131131
NonNull::new(ptr.cast_mut())
132132
.map(|p| PoolDevicePathNode(PoolAllocation::new(p.cast())))
133-
.ok_or(Status::OUT_OF_RESOURCES.into())
133+
.ok_or_else(|| Status::OUT_OF_RESOURCES.into())
134134
}
135135
}
136136

@@ -147,7 +147,7 @@ impl DevicePathFromText {
147147
let ptr = (self.0.convert_text_to_device_path)(text_device_path.as_ptr().cast());
148148
NonNull::new(ptr.cast_mut())
149149
.map(|p| PoolDevicePath(PoolAllocation::new(p.cast())))
150-
.ok_or(Status::OUT_OF_RESOURCES.into())
150+
.ok_or_else(|| Status::OUT_OF_RESOURCES.into())
151151
}
152152
}
153153
}

‎uefi/src/proto/device_path/util.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl DevicePathUtilities {
4848
(self.0.append_device_path)(path0.as_ffi_ptr().cast(), path1.as_ffi_ptr().cast());
4949
NonNull::new(ptr.cast_mut())
5050
.map(|p| PoolDevicePath(PoolAllocation::new(p.cast())))
51-
.ok_or(Status::OUT_OF_RESOURCES.into())
51+
.ok_or_else(|| Status::OUT_OF_RESOURCES.into())
5252
}
5353
}
5454

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

@@ -96,7 +96,7 @@ impl DevicePathUtilities {
9696
);
9797
NonNull::new(ptr.cast_mut())
9898
.map(|p| PoolDevicePath(PoolAllocation::new(p.cast())))
99-
.ok_or(Status::OUT_OF_RESOURCES.into())
99+
.ok_or_else(|| Status::OUT_OF_RESOURCES.into())
100100
}
101101
}
102102
}

‎uefi/src/proto/hii/config_str.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl<'a> Iterator for ConfigurationStringIter<'a> {
4242
let (keyval, remainder) = self
4343
.bfr
4444
.split_once('&')
45-
.unwrap_or((self.bfr, &self.bfr[0..0]));
45+
.unwrap_or_else(|| (self.bfr, &self.bfr[0..0]));
4646
self.bfr = remainder;
4747
let (key, value) = keyval
4848
.split_once('=')

‎uefi/src/proto/nvme/pass_thru.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl NvmeNamespace<'_> {
142142
.to_result()?;
143143
NonNull::new(path_ptr.cast_mut())
144144
.map(|p| PoolDevicePathNode(PoolAllocation::new(p.cast())))
145-
.ok_or(Status::OUT_OF_RESOURCES.into())
145+
.ok_or_else(|| Status::OUT_OF_RESOURCES.into())
146146
}
147147
}
148148

‎uefi/src/proto/scsi/pass_thru.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl ScsiDevice<'_> {
162162
.to_result()?;
163163
NonNull::new(path_ptr.cast_mut())
164164
.map(|p| PoolDevicePathNode(PoolAllocation::new(p.cast())))
165-
.ok_or(Status::OUT_OF_RESOURCES.into())
165+
.ok_or_else(|| Status::OUT_OF_RESOURCES.into())
166166
}
167167
}
168168

‎uefi/src/runtime.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -844,12 +844,12 @@ impl TryFrom<&[u8]> for Time {
844844
Self::UNSPECIFIED_TIMEZONE => None,
845845
num => Some(num),
846846
};
847-
let daylight = Daylight::from_bits(bytes[14]).ok_or(
847+
let daylight = Daylight::from_bits(bytes[14]).ok_or_else(|| {
848848
TimeByteConversionError::InvalidFields(TimeError {
849849
daylight: true,
850850
..Default::default()
851-
}),
852-
)?;
851+
})
852+
})?;
853853

854854
let time_params = TimeParams {
855855
year,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /