From 198cc1abb1e04d81c1d7b2437934c6c882cd426e Mon Sep 17 00:00:00 2001 From: Boqun Feng Date: Mon, 25 Mar 2024 15:00:10 -0700 Subject: [PATCH] TEMP: rust: Adjustment of allocation API changes Signed-off-by: Boqun Feng --- rust/kernel/file.rs | 15 ++++++++++----- rust/kernel/sync/arc.rs | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/rust/kernel/file.rs b/rust/kernel/file.rs index 8902f490ccc841..bf68a0ce9f14fd 100644 --- a/rust/kernel/file.rs +++ b/rust/kernel/file.rs @@ -6,13 +6,15 @@ //! [`include/linux/file.h`](srctree/include/linux/file.h) use crate::{ + alloc::AllocError, bindings, cred::Credential, error::{code::*, Error, Result}, + prelude::*, types::{ARef, AlwaysRefCounted, NotThreadSafe, Opaque}, }; use alloc::boxed::Box; -use core::{alloc::AllocError, mem, ptr}; +use core::{mem, ptr}; /// Flags associated with a [`File`]. pub mod flags { @@ -348,10 +350,13 @@ impl DeferredFdCloser { pub fn new() -> Result { Ok(Self { // INVARIANT: The `file` pointer is null, so the type invariant does not apply. - inner: Box::try_new(DeferredFdCloserInner { - twork: mem::MaybeUninit::uninit(), - file: core::ptr::null_mut(), - })?, + inner: as BoxExt<_>>::new( + DeferredFdCloserInner { + twork: mem::MaybeUninit::uninit(), + file: core::ptr::null_mut(), + }, + GFP_KERNEL, + )?, }) } diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs index c4a5e175b57401..13a2166c4f410c 100644 --- a/rust/kernel/sync/arc.rs +++ b/rust/kernel/sync/arc.rs @@ -302,7 +302,7 @@ impl Arc { /// ``` /// use kernel::sync::{Arc, UniqueArc}; /// - /// let arc = Arc::try_new(42)?; + /// let arc = Arc::new(42, GFP_KERNEL)?; /// let unique_arc = arc.into_unique_or_drop(); /// /// // The above conversion should succeed since refcount of `arc` is 1. @@ -316,7 +316,7 @@ impl Arc { /// ``` /// use kernel::sync::{Arc, UniqueArc}; /// - /// let arc = Arc::try_new(42)?; + /// let arc = Arc::new(42, GFP_KERNEL)?; /// let another = arc.clone(); /// /// let unique_arc = arc.into_unique_or_drop();