From d0f65424d73d530db264430345f96332a65d167a Mon Sep 17 00:00:00 2001 From: Danilo Krummrich Date: Mon, 24 Jun 2024 20:44:33 +0200 Subject: rust: treewide: nova-next: switch to `KBox` Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/nova/file.rs | 6 +++--- rust/kernel/drm/file.rs | 9 ++++----- rust/kernel/drm/gem/mod.rs | 12 +++++------- rust/kernel/revocable.rs | 6 ++++-- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/nova/file.rs b/drivers/gpu/drm/nova/file.rs index 4fa9df536f78..ac4eac6a08f2 100644 --- a/drivers/gpu/drm/nova/file.rs +++ b/drivers/gpu/drm/nova/file.rs @@ -3,7 +3,7 @@ use crate::driver::{NovaDevice, NovaDriver}; use crate::gem; use kernel::{ - alloc::flags::*, + alloc::{flags::*, KBox}, drm::{self, device::Device as DrmDevice, gem::BaseObject}, prelude::*, uapi, @@ -17,10 +17,10 @@ pub(crate) type DrmFile = drm::file::File; impl drm::file::DriverFile for File { type Driver = NovaDriver; - fn open(dev: &DrmDevice) -> Result>> { + fn open(dev: &DrmDevice) -> Result>> { dev_dbg!(dev.as_ref(), "drm::device::Device::open\n"); - Ok(Box::into_pin(Box::new(Self(), GFP_KERNEL)?)) + Ok(KBox::into_pin(KBox::new(Self(), GFP_KERNEL)?)) } } diff --git a/rust/kernel/drm/file.rs b/rust/kernel/drm/file.rs index 0b6366734c61..523ce136226e 100644 --- a/rust/kernel/drm/file.rs +++ b/rust/kernel/drm/file.rs @@ -4,8 +4,7 @@ //! //! C header: [`include/linux/drm/drm_file.h`](srctree/include/linux/drm/drm_file.h) -use crate::{bindings, drm, error::Result}; -use alloc::boxed::Box; +use crate::{alloc::KBox, bindings, drm, error::Result}; use core::marker::PhantomData; use core::pin::Pin; @@ -15,7 +14,7 @@ pub trait DriverFile { type Driver: drm::drv::Driver; /// Open a new file (called when a client opens the DRM device). - fn open(device: &drm::device::Device) -> Result>>; + fn open(device: &drm::device::Device) -> Result>>; } /// An open DRM File. @@ -45,7 +44,7 @@ pub(super) unsafe extern "C" fn open_callback( }; // SAFETY: This pointer is treated as pinned, and the Drop guarantee is upheld below. - file.driver_priv = Box::into_raw(unsafe { Pin::into_inner_unchecked(inner) }) as *mut _; + file.driver_priv = KBox::into_raw(unsafe { Pin::into_inner_unchecked(inner) }) as *mut _; 0 } @@ -60,7 +59,7 @@ pub(super) unsafe extern "C" fn postclose_callback( // Drop the DriverFile unsafe { - let _ = Box::from_raw(file.driver_priv as *mut T); + let _ = KBox::from_raw(file.driver_priv as *mut T); }; } diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs index b5208fdf66c2..b569ac5eec5e 100644 --- a/rust/kernel/drm/gem/mod.rs +++ b/rust/kernel/drm/gem/mod.rs @@ -4,10 +4,8 @@ //! //! C header: [`include/linux/drm/drm_gem.h`](srctree/include/linux/drm/drm_gem.h) -use alloc::boxed::Box; - use crate::{ - alloc::flags::*, + alloc::{flags::*, KBox}, bindings, drm::{device, drv, file}, error::{to_result, Result}, @@ -66,7 +64,7 @@ unsafe extern "C" fn free_callback(obj: *mut bindings::drm_gem_ // free callback which guarantees this object has zero remaining references, // so we can drop it unsafe { - let _ = Box::from_raw(this); + let _ = KBox::from_raw(this); }; } @@ -229,7 +227,7 @@ impl Object { /// Create a new GEM object. pub fn new(dev: &device::Device, size: usize) -> Result>> { - let obj: Pin> = Box::pin_init( + let obj: Pin> = KBox::pin_init( try_pin_init!(Self { // SAFETY: This struct is expected to be zero-initialized obj: bindings::drm_gem_object { @@ -252,8 +250,8 @@ impl Object { // SAFETY: We never move out of self let obj_ref = unsafe { Pin::new_unchecked(UniqueObjectRef { - // SAFETY: We never move out of the Box - ptr: Box::leak(Pin::into_inner_unchecked(obj)), + // SAFETY: We never move out of the KBox + ptr: KBox::leak(Pin::into_inner_unchecked(obj)), _p: PhantomPinned, }) }; diff --git a/rust/kernel/revocable.rs b/rust/kernel/revocable.rs index 3d13e7b2f2e8..f54f6d673f72 100644 --- a/rust/kernel/revocable.rs +++ b/rust/kernel/revocable.rs @@ -29,6 +29,7 @@ use core::{ /// /// ``` /// # use kernel::revocable::Revocable; +/// use kernel::alloc::KBox; /// /// struct Example { /// a: u32, @@ -40,7 +41,7 @@ use core::{ /// Some(guard.a + guard.b) /// } /// -/// let v = Box::pin_init(Revocable::new(Example { a: 10, b: 20 }), GFP_KERNEL).unwrap(); +/// let v = KBox::pin_init(Revocable::new(Example { a: 10, b: 20 }), GFP_KERNEL).unwrap(); /// assert_eq!(add_two(&v), Some(30)); /// v.revoke(); /// assert_eq!(add_two(&v), None); @@ -50,6 +51,7 @@ use core::{ /// /// ``` /// # use kernel::revocable::Revocable; +/// use kernel::alloc::KBox; /// use kernel::sync::rcu; /// /// struct Example { @@ -63,7 +65,7 @@ use core::{ /// Some(e.a + e.b) /// } /// -/// let v = Box::pin_init(Revocable::new(Example { a: 10, b: 20 }), GFP_KERNEL).unwrap(); +/// let v = KBox::pin_init(Revocable::new(Example { a: 10, b: 20 }), GFP_KERNEL).unwrap(); /// assert_eq!(add_two(&v), Some(30)); /// v.revoke(); /// assert_eq!(add_two(&v), None); -- cgit v1.2.3-58-ga151