[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250130185138.200993-1-trintaeoitogc@gmail.com>
Date: Thu, 30 Jan 2025 15:51:38 -0300
From: Guilherme Giacomo Simoes <trintaeoitogc@...il.com>
To: peterz@...radead.org,
mingo@...hat.com,
will@...nel.org,
boqun.feng@...il.com,
longman@...hat.com,
ojeda@...nel.org,
alex.gaynor@...il.com,
gary@...yguo.net,
bjorn3_gh@...tonmail.com,
benno.lossin@...ton.me,
a.hindborg@...nel.org,
aliceryhl@...gle.com,
tmgross@...ch.edu
Cc: Guilherme Giacomo Simoes <trintaeoitogc@...il.com>,
linux-kernel@...r.kernel.org,
rust-for-linux@...r.kernel.org
Subject: [PATCH] rust: sync: create the `get_mut()` function
Create a `get_mut()` function that receive a mutable instance of Lock,
and return a mutable reference to data because if the instance is
mutable, the rust compiler guarantee the access control.
Suggested-by: Björn Roy Baron <bjorn3_gh@...tonmail.com>
Signed-off-by: Guilherme Giacomo Simoes <trintaeoitogc@...il.com>
---
rust/kernel/sync/lock.rs | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs
index eb80048e0110..3f9d78bcb37c 100644
--- a/rust/kernel/sync/lock.rs
+++ b/rust/kernel/sync/lock.rs
@@ -140,6 +140,12 @@ pub fn new(t: T, name: &'static CStr, key: &'static LockClassKey) -> impl PinIni
}),
})
}
+
+ /// Get a mutable reference to data
+ pub fn get_mut(&mut self) -> &mut T {
+ // SAFETY: the caller must guarantee that the instance is only used in one place
+ unsafe { &mut *self.data.get() }
+ }
}
impl<B: Backend> Lock<(), B> {
--
2.34.1
Powered by blists - more mailing lists