Skip to content

Commit 11af6e1

Browse files
yilin0518vireshk
authored andcommitted
rust: cpumask: rename methods of Cpumask for clarity and consistency
Rename `as_ref` and `as_mut_ref` to `from_raw` and `from_raw_mut` to align with the established naming convention for constructing types from raw pointers in the kernel's Rust codebase. Signed-off-by: Yilin Chen <1479826151@qq.com> Reviewed-by: Gary Guo <gary@garyguo.net> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
1 parent 997c021 commit 11af6e1

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

rust/kernel/cpumask.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use core::ops::{Deref, DerefMut};
3939
/// fn set_clear_cpu(ptr: *mut bindings::cpumask, set_cpu: CpuId, clear_cpu: CpuId) {
4040
/// // SAFETY: The `ptr` is valid for writing and remains valid for the lifetime of the
4141
/// // returned reference.
42-
/// let mask = unsafe { Cpumask::as_mut_ref(ptr) };
42+
/// let mask = unsafe { Cpumask::from_raw_mut(ptr) };
4343
///
4444
/// mask.set(set_cpu);
4545
/// mask.clear(clear_cpu);
@@ -49,27 +49,27 @@ use core::ops::{Deref, DerefMut};
4949
pub struct Cpumask(Opaque<bindings::cpumask>);
5050

5151
impl Cpumask {
52-
/// Creates a mutable reference to an existing `struct cpumask` pointer.
52+
/// Creates a mutable reference from an existing `struct cpumask` pointer.
5353
///
5454
/// # Safety
5555
///
5656
/// The caller must ensure that `ptr` is valid for writing and remains valid for the lifetime
5757
/// of the returned reference.
58-
pub unsafe fn as_mut_ref<'a>(ptr: *mut bindings::cpumask) -> &'a mut Self {
58+
pub unsafe fn from_raw_mut<'a>(ptr: *mut bindings::cpumask) -> &'a mut Self {
5959
// SAFETY: Guaranteed by the safety requirements of the function.
6060
//
6161
// INVARIANT: The caller ensures that `ptr` is valid for writing and remains valid for the
6262
// lifetime of the returned reference.
6363
unsafe { &mut *ptr.cast() }
6464
}
6565

66-
/// Creates a reference to an existing `struct cpumask` pointer.
66+
/// Creates a reference from an existing `struct cpumask` pointer.
6767
///
6868
/// # Safety
6969
///
7070
/// The caller must ensure that `ptr` is valid for reading and remains valid for the lifetime
7171
/// of the returned reference.
72-
pub unsafe fn as_ref<'a>(ptr: *const bindings::cpumask) -> &'a Self {
72+
pub unsafe fn from_raw<'a>(ptr: *const bindings::cpumask) -> &'a Self {
7373
// SAFETY: Guaranteed by the safety requirements of the function.
7474
//
7575
// INVARIANT: The caller ensures that `ptr` is valid for reading and remains valid for the

0 commit comments

Comments
 (0)