rust/kernel/cpumask.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
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>
---
Changes in v3:
- Use real name in signed-off-by line (Kari Argillander)
- Add links to priveous patches:
- Link to v2: https://lore.kernel.org/rust-for-linux/tencent_58EDE157C8C700CFF88DA204B7492A113508@qq.com/
Changes in v2:
- Use real name in From line (Alice Ryhl)
- Send this patch individually instead of bundling with others
- Link to v1: https://lore.kernel.org/rust-for-linux/aUMUA_JWalyGQdAx@google.com/#t
---
rust/kernel/cpumask.rs | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/rust/kernel/cpumask.rs b/rust/kernel/cpumask.rs
index c1d17826ae7b..44bb36636ee3 100644
--- a/rust/kernel/cpumask.rs
+++ b/rust/kernel/cpumask.rs
@@ -39,7 +39,7 @@
/// fn set_clear_cpu(ptr: *mut bindings::cpumask, set_cpu: CpuId, clear_cpu: CpuId) {
/// // SAFETY: The `ptr` is valid for writing and remains valid for the lifetime of the
/// // returned reference.
-/// let mask = unsafe { Cpumask::as_mut_ref(ptr) };
+/// let mask = unsafe { Cpumask::from_raw_mut(ptr) };
///
/// mask.set(set_cpu);
/// mask.clear(clear_cpu);
@@ -49,13 +49,13 @@
pub struct Cpumask(Opaque<bindings::cpumask>);
impl Cpumask {
- /// Creates a mutable reference to an existing `struct cpumask` pointer.
+ /// Creates a mutable reference from an existing `struct cpumask` pointer.
///
/// # Safety
///
/// The caller must ensure that `ptr` is valid for writing and remains valid for the lifetime
/// of the returned reference.
- pub unsafe fn as_mut_ref<'a>(ptr: *mut bindings::cpumask) -> &'a mut Self {
+ pub unsafe fn from_raw_mut<'a>(ptr: *mut bindings::cpumask) -> &'a mut Self {
// SAFETY: Guaranteed by the safety requirements of the function.
//
// INVARIANT: The caller ensures that `ptr` is valid for writing and remains valid for the
@@ -63,13 +63,13 @@ pub unsafe fn as_mut_ref<'a>(ptr: *mut bindings::cpumask) -> &'a mut Self {
unsafe { &mut *ptr.cast() }
}
- /// Creates a reference to an existing `struct cpumask` pointer.
+ /// Creates a reference from an existing `struct cpumask` pointer.
///
/// # Safety
///
/// The caller must ensure that `ptr` is valid for reading and remains valid for the lifetime
/// of the returned reference.
- pub unsafe fn as_ref<'a>(ptr: *const bindings::cpumask) -> &'a Self {
+ pub unsafe fn from_raw<'a>(ptr: *const bindings::cpumask) -> &'a Self {
// SAFETY: Guaranteed by the safety requirements of the function.
//
// INVARIANT: The caller ensures that `ptr` is valid for reading and remains valid for the
--
2.34.1
+ Yury.
Yilin, please use scripts/get_maintainer.pl in future to get the list
of all relevant people.
On 12-01-26, 16:00, Yilin Chen wrote:
> 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>
> ---
> Changes in v3:
> - Use real name in signed-off-by line (Kari Argillander)
> - Add links to priveous patches:
> - Link to v2: https://lore.kernel.org/rust-for-linux/tencent_58EDE157C8C700CFF88DA204B7492A113508@qq.com/
>
> Changes in v2:
> - Use real name in From line (Alice Ryhl)
> - Send this patch individually instead of bundling with others
> - Link to v1: https://lore.kernel.org/rust-for-linux/aUMUA_JWalyGQdAx@google.com/#t
> ---
> rust/kernel/cpumask.rs | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/rust/kernel/cpumask.rs b/rust/kernel/cpumask.rs
> index c1d17826ae7b..44bb36636ee3 100644
> --- a/rust/kernel/cpumask.rs
> +++ b/rust/kernel/cpumask.rs
> @@ -39,7 +39,7 @@
> /// fn set_clear_cpu(ptr: *mut bindings::cpumask, set_cpu: CpuId, clear_cpu: CpuId) {
> /// // SAFETY: The `ptr` is valid for writing and remains valid for the lifetime of the
> /// // returned reference.
> -/// let mask = unsafe { Cpumask::as_mut_ref(ptr) };
> +/// let mask = unsafe { Cpumask::from_raw_mut(ptr) };
> ///
> /// mask.set(set_cpu);
> /// mask.clear(clear_cpu);
> @@ -49,13 +49,13 @@
> pub struct Cpumask(Opaque<bindings::cpumask>);
>
> impl Cpumask {
> - /// Creates a mutable reference to an existing `struct cpumask` pointer.
> + /// Creates a mutable reference from an existing `struct cpumask` pointer.
> ///
> /// # Safety
> ///
> /// The caller must ensure that `ptr` is valid for writing and remains valid for the lifetime
> /// of the returned reference.
> - pub unsafe fn as_mut_ref<'a>(ptr: *mut bindings::cpumask) -> &'a mut Self {
> + pub unsafe fn from_raw_mut<'a>(ptr: *mut bindings::cpumask) -> &'a mut Self {
> // SAFETY: Guaranteed by the safety requirements of the function.
> //
> // INVARIANT: The caller ensures that `ptr` is valid for writing and remains valid for the
> @@ -63,13 +63,13 @@ pub unsafe fn as_mut_ref<'a>(ptr: *mut bindings::cpumask) -> &'a mut Self {
> unsafe { &mut *ptr.cast() }
> }
>
> - /// Creates a reference to an existing `struct cpumask` pointer.
> + /// Creates a reference from an existing `struct cpumask` pointer.
> ///
> /// # Safety
> ///
> /// The caller must ensure that `ptr` is valid for reading and remains valid for the lifetime
> /// of the returned reference.
> - pub unsafe fn as_ref<'a>(ptr: *const bindings::cpumask) -> &'a Self {
> + pub unsafe fn from_raw<'a>(ptr: *const bindings::cpumask) -> &'a Self {
> // SAFETY: Guaranteed by the safety requirements of the function.
> //
> // INVARIANT: The caller ensures that `ptr` is valid for reading and remains valid for the
Applied. Thanks.
--
viresh
On Mon Jan 12, 2026 at 8:00 AM GMT, Yilin Chen wrote: > 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> > --- > Changes in v3: > - Use real name in signed-off-by line (Kari Argillander) > - Add links to priveous patches: > - Link to v2: https://lore.kernel.org/rust-for-linux/tencent_58EDE157C8C700CFF88DA204B7492A113508@qq.com/ > > Changes in v2: > - Use real name in From line (Alice Ryhl) > - Send this patch individually instead of bundling with others > - Link to v1: https://lore.kernel.org/rust-for-linux/aUMUA_JWalyGQdAx@google.com/#t > --- > rust/kernel/cpumask.rs | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-)
On Mon, Jan 12, 2026 at 04:00:47PM +0800, Yilin Chen wrote: > 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: Alice Ryhl <aliceryhl@google.com> Thanks!
© 2016 - 2026 Red Hat, Inc.