From: Antonio Hickey <contact@antoniohickey.com>
To: "Benno Lossin" <benno.lossin@proton.me>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>
Cc: Antonio Hickey <contact@antoniohickey.com>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v6 01/18] rust: init: refactor to use `&raw mut`
Date: Thu, 17 Apr 2025 21:41:22 -0400 [thread overview]
Message-ID: <20250418014143.888022-2-contact@antoniohickey.com> (raw)
In-Reply-To: <20250418014143.888022-1-contact@antoniohickey.com>
Replacing all occurrences of `addr_of_mut!(place)`
with `&raw mut place`.
This will allow us to reduce macro complexity, and improve consistency
with existing reference syntax as `&raw mut` is similar to `&mut`
making it fit more naturally with other existing code.
Suggested-by: Benno Lossin <benno.lossin@proton.me>
Link: https://github.com/Rust-for-Linux/linux/issues/1148
Signed-off-by: Antonio Hickey <contact@antoniohickey.com>
---
rust/kernel/init.rs | 4 ++--
rust/pin-init/src/macros.rs | 12 ++++++------
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/rust/kernel/init.rs b/rust/kernel/init.rs
index 8d228c237954..5646b1079776 100644
--- a/rust/kernel/init.rs
+++ b/rust/kernel/init.rs
@@ -69,7 +69,7 @@
//! ```rust,ignore
//! # #![allow(unreachable_pub, clippy::disallowed_names)]
//! use kernel::{prelude::*, types::Opaque};
-//! use core::{ptr::addr_of_mut, marker::PhantomPinned, pin::Pin};
+//! use core::{marker::PhantomPinned, pin::Pin};
//! # mod bindings {
//! # #![allow(non_camel_case_types)]
//! # pub struct foo;
@@ -105,7 +105,7 @@
//! unsafe {
//! pin_init::pin_init_from_closure(move |slot: *mut Self| {
//! // `slot` contains uninit memory, avoid creating a reference.
-//! let foo = addr_of_mut!((*slot).foo);
+//! let foo = &raw mut (*slot).foo;
//!
//! // Initialize the `foo`
//! bindings::init_foo(Opaque::raw_get(foo));
diff --git a/rust/pin-init/src/macros.rs b/rust/pin-init/src/macros.rs
index 361623324d5c..28a91a1e1218 100644
--- a/rust/pin-init/src/macros.rs
+++ b/rust/pin-init/src/macros.rs
@@ -244,7 +244,7 @@
//! struct __InitOk;
//! // This is the expansion of `t,`, which is syntactic sugar for `t: t,`.
//! {
-//! unsafe { ::core::ptr::write(::core::addr_of_mut!((*slot).t), t) };
+//! unsafe { ::core::ptr::write(&raw mut (*slot).t, t) };
//! }
//! // Since initialization could fail later (not in this case, since the
//! // error type is `Infallible`) we will need to drop this field if there
@@ -258,7 +258,7 @@
//! // of the `unsafe` block, so we bind it here.
//! {
//! let x = 0;
-//! unsafe { ::core::ptr::write(::core::addr_of_mut!((*slot).x), x) };
+//! unsafe { ::core::ptr::write(&raw mut (*slot).x, x) };
//! }
//! // We again create a `DropGuard`.
//! let __x_guard = unsafe {
@@ -459,13 +459,13 @@
//! {
//! struct __InitOk;
//! {
-//! unsafe { ::core::ptr::write(::core::addr_of_mut!((*slot).a), a) };
+//! unsafe { ::core::ptr::write(&raw mut (*slot).a, a) };
//! }
//! let __a_guard = unsafe {
//! ::pin_init::__internal::DropGuard::new(::core::addr_of_mut!((*slot).a))
//! };
//! let init = Bar::new(36);
-//! unsafe { data.b(::core::addr_of_mut!((*slot).b), b)? };
+//! unsafe { data.b(&raw mut (*slot).b, b)? };
//! let __b_guard = unsafe {
//! ::pin_init::__internal::DropGuard::new(::core::addr_of_mut!((*slot).b))
//! };
@@ -1215,7 +1215,7 @@ fn assert_zeroable<T: $crate::Zeroable>(_: *mut T) {}
// SAFETY: `slot` is valid, because we are inside of an initializer closure, we
// return when an error/panic occurs.
// We also use the `data` to require the correct trait (`Init` or `PinInit`) for `$field`.
- unsafe { $data.$field(::core::ptr::addr_of_mut!((*$slot).$field), init)? };
+ unsafe { $data.$field(&raw mut (*$slot).$field, init)? };
// Create the drop guard:
//
// We rely on macro hygiene to make it impossible for users to access this local variable.
@@ -1277,7 +1277,7 @@ fn assert_zeroable<T: $crate::Zeroable>(_: *mut T) {}
// Initialize the field.
//
// SAFETY: The memory at `slot` is uninitialized.
- unsafe { ::core::ptr::write(::core::ptr::addr_of_mut!((*$slot).$field), $field) };
+ unsafe { ::core::ptr::write(&raw mut (*$slot).$field, $field) };
}
// Create the drop guard:
//
--
2.48.1
next prev parent reply other threads:[~2025-04-18 1:42 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-18 1:41 [PATCH v6 00/18] refactor to utilize `&raw [const|mut]` Antonio Hickey
2025-04-18 1:41 ` Antonio Hickey [this message]
2025-04-21 20:20 ` [PATCH v6 01/18] rust: init: refactor to use `&raw mut` Benno Lossin
2025-04-18 1:41 ` [PATCH v6 02/18] rust: list: refactor to use `&raw [const|mut]` Antonio Hickey
2025-04-18 1:41 ` [PATCH v6 03/18] rust: task: remove use of `addr_of!` macro Antonio Hickey
2025-04-18 1:41 ` [PATCH v6 04/18] rust: faux: refactor to use `&raw mut` Antonio Hickey
2025-04-18 1:41 ` [PATCH v6 05/18] rust: kunit: refactor to use `&raw [const|mut]` Antonio Hickey
2025-04-18 1:41 ` [PATCH v6 06/18] rust: workqueue: " Antonio Hickey
2025-04-18 1:41 ` [PATCH v6 07/18] rust: workqueue: replace `raw_get` with pointer cast Antonio Hickey
2025-04-18 1:41 ` [PATCH v6 08/18] rust: rbtree: refactor to use `&raw mut` Antonio Hickey
2025-04-18 1:41 ` [PATCH v6 09/18] rust: net: phy: " Antonio Hickey
2025-04-18 1:41 ` [PATCH v6 10/18] rust: sync: arc: refactor to use `&raw const` Antonio Hickey
2025-04-18 1:41 ` [PATCH v6 11/18] rust: jump_label: " Antonio Hickey
2025-04-18 1:41 ` [PATCH v6 12/18] rust: fs: file: " Antonio Hickey
2025-04-18 1:41 ` [PATCH v6 13/18] rust: time: hrtimer: " Antonio Hickey
2025-04-18 1:41 ` [PATCH v6 14/18] rust: pci: refactor to use `&raw mut` Antonio Hickey
2025-04-18 1:41 ` [PATCH v6 15/18] rust: platform: " Antonio Hickey
2025-04-18 1:41 ` [PATCH v6 16/18] rust: dma: refactor to use `&raw [const|mut]` Antonio Hickey
2025-04-18 1:41 ` [PATCH v6 17/18] rust: pin-init: refactor to use `&raw mut` Antonio Hickey
2025-04-18 1:41 ` [PATCH v6 18/18] rust: clippy: disallow `addr_of[_mut]!` macros Antonio Hickey
2025-04-18 13:45 ` [PATCH v6 00/18] refactor to utilize `&raw [const|mut]` Miguel Ojeda
2025-09-08 11:23 ` Miguel Ojeda
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250418014143.888022-2-contact@antoniohickey.com \
--to=contact@antoniohickey.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.