Skip to content

Commit 3fd100b

Browse files
committed
rust: kernel: use the new try_* methods
In preparation for enabling `no_global_oom_handling` for `alloc`, we need to stop using methods that will disappear when enabling the configuration option. Instead, we use the new methods we just added. Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 487d757 commit 3fd100b

File tree

4 files changed

+4
-6
lines changed

4 files changed

+4
-6
lines changed

rust/kernel/io_buffer.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ pub trait IoBufferReader {
3030
/// Returns `EFAULT` if the address does not currently point to mapped, readable memory.
3131
fn read_all(&mut self) -> Result<Vec<u8>> {
3232
let mut data = Vec::<u8>::new();
33-
data.try_reserve_exact(self.len())?;
34-
data.resize(self.len(), 0);
33+
data.try_resize(self.len(), 0)?;
3534

3635
// SAFETY: The output buffer is valid as we just allocated it.
3736
unsafe { self.read_raw(data.as_mut_ptr(), data.len())? };

rust/kernel/module_param.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,7 @@ impl ModuleParam for StringParam {
476476
arg.and_then(|arg| {
477477
if slab_available {
478478
let mut vec = alloc::vec::Vec::new();
479-
vec.try_reserve_exact(arg.len()).ok()?;
480-
vec.extend_from_slice(arg);
479+
vec.try_extend_from_slice(arg).ok()?;
481480
Some(StringParam::Owned(vec))
482481
} else {
483482
Some(StringParam::Ref(arg))

rust/kernel/sysctl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl<T: SysctlStorage> Sysctl<T> {
156156
},
157157
unsafe { mem::zeroed() },
158158
]
159-
.into_boxed_slice();
159+
.try_into_boxed_slice()?;
160160

161161
let result = unsafe { bindings::register_sysctl(path.as_char_ptr(), table.as_mut_ptr()) };
162162
if result.is_null() {

samples/rust/rust_minimal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl KernelModule for RustMinimal {
2525
pr_info!("Am I built-in? {}\n", !cfg!(MODULE));
2626

2727
Ok(RustMinimal {
28-
message: "on the heap!".to_owned(),
28+
message: "on the heap!".try_to_owned()?,
2929
})
3030
}
3131
}

0 commit comments

Comments
 (0)