mirror of
https://github.com/torvalds/linux.git
synced 2025-12-07 20:06:24 +00:00
rust: debugfs: Replace the usage of Rust native atomics
Rust native atomics are not allowed to use in kernel due to the mismatch of memory model with Linux kernel memory model, hence remove the usage of Rust native atomics in debufs. Reviewed-by: Matthew Maurer <mmaurer@google.com> Acked-by: Danilo Krummrich <dakr@kernel.org> Tested-by: David Gow <davidgow@google.com> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Link: https://patch.msgid.link/20251022035324.70785-4-boqun.feng@gmail.com
This commit is contained in:
@@ -32,14 +32,12 @@
|
||||
//! ```
|
||||
|
||||
use core::str::FromStr;
|
||||
use core::sync::atomic::AtomicUsize;
|
||||
use core::sync::atomic::Ordering;
|
||||
use kernel::c_str;
|
||||
use kernel::debugfs::{Dir, File};
|
||||
use kernel::new_mutex;
|
||||
use kernel::prelude::*;
|
||||
use kernel::sync::atomic::{Atomic, Relaxed};
|
||||
use kernel::sync::Mutex;
|
||||
|
||||
use kernel::{acpi, device::Core, of, platform, str::CString, types::ARef};
|
||||
|
||||
kernel::module_platform_driver! {
|
||||
@@ -59,7 +57,7 @@ struct RustDebugFs {
|
||||
#[pin]
|
||||
_compatible: File<CString>,
|
||||
#[pin]
|
||||
counter: File<AtomicUsize>,
|
||||
counter: File<Atomic<usize>>,
|
||||
#[pin]
|
||||
inner: File<Mutex<Inner>>,
|
||||
}
|
||||
@@ -109,7 +107,7 @@ impl platform::Driver for RustDebugFs {
|
||||
) -> Result<Pin<KBox<Self>>> {
|
||||
let result = KBox::try_pin_init(RustDebugFs::new(pdev), GFP_KERNEL)?;
|
||||
// We can still mutate fields through the files which are atomic or mutexed:
|
||||
result.counter.store(91, Ordering::Relaxed);
|
||||
result.counter.store(91, Relaxed);
|
||||
{
|
||||
let mut guard = result.inner.lock();
|
||||
guard.x = guard.y;
|
||||
@@ -120,8 +118,8 @@ impl platform::Driver for RustDebugFs {
|
||||
}
|
||||
|
||||
impl RustDebugFs {
|
||||
fn build_counter(dir: &Dir) -> impl PinInit<File<AtomicUsize>> + '_ {
|
||||
dir.read_write_file(c_str!("counter"), AtomicUsize::new(0))
|
||||
fn build_counter(dir: &Dir) -> impl PinInit<File<Atomic<usize>>> + '_ {
|
||||
dir.read_write_file(c_str!("counter"), Atomic::<usize>::new(0))
|
||||
}
|
||||
|
||||
fn build_inner(dir: &Dir) -> impl PinInit<File<Mutex<Inner>>> + '_ {
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
//! `Scope::dir` to create a variety of files without the need to separately
|
||||
//! track them all.
|
||||
|
||||
use core::sync::atomic::AtomicUsize;
|
||||
use kernel::debugfs::{Dir, Scope};
|
||||
use kernel::prelude::*;
|
||||
use kernel::sync::atomic::Atomic;
|
||||
use kernel::sync::Mutex;
|
||||
use kernel::{c_str, new_mutex, str::CString};
|
||||
|
||||
@@ -62,7 +62,7 @@ fn create_file_write(
|
||||
let file_name = CString::try_from_fmt(fmt!("{name_str}"))?;
|
||||
for sub in items {
|
||||
nums.push(
|
||||
AtomicUsize::new(sub.parse().map_err(|_| EINVAL)?),
|
||||
Atomic::<usize>::new(sub.parse().map_err(|_| EINVAL)?),
|
||||
GFP_KERNEL,
|
||||
)?;
|
||||
}
|
||||
@@ -109,7 +109,7 @@ impl ModuleData {
|
||||
|
||||
struct DeviceData {
|
||||
name: CString,
|
||||
nums: KVec<AtomicUsize>,
|
||||
nums: KVec<Atomic<usize>>,
|
||||
}
|
||||
|
||||
fn init_control(base_dir: &Dir, dyn_dirs: Dir) -> impl PinInit<Scope<ModuleData>> + '_ {
|
||||
|
||||
Reference in New Issue
Block a user