summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drivers/gpu/drm/nova/file.rs6
-rw-r--r--rust/kernel/drm/file.rs9
-rw-r--r--rust/kernel/drm/gem/mod.rs12
-rw-r--r--rust/kernel/revocable.rs6
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<File>;
impl drm::file::DriverFile for File {
type Driver = NovaDriver;
- fn open(dev: &DrmDevice<Self::Driver>) -> Result<Pin<Box<Self>>> {
+ fn open(dev: &DrmDevice<Self::Driver>) -> Result<Pin<KBox<Self>>> {
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<Self::Driver>) -> Result<Pin<Box<Self>>>;
+ fn open(device: &drm::device::Device<Self::Driver>) -> Result<Pin<KBox<Self>>>;
}
/// An open DRM File.
@@ -45,7 +44,7 @@ pub(super) unsafe extern "C" fn open_callback<T: DriverFile>(
};
// 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<T: DriverFile>(
// 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<T: DriverObject>(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<T: DriverObject> Object<T> {
/// Create a new GEM object.
pub fn new(dev: &device::Device<T::Driver>, size: usize) -> Result<Pin<UniqueObjectRef<Self>>> {
- let obj: Pin<Box<Self>> = Box::pin_init(
+ let obj: Pin<KBox<Self>> = 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<T: DriverObject> Object<T> {
// 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);