Re: [PATCH 3/3] rust: replace `addr_of[_mut]!` with `&raw [mut]`

From: Benno Lossin <hidden>
Date: 2025-03-13 12:20:18
Also in: linux-kselftest, linux-pci, lkml, netdev, rust-for-linux

On Thu Mar 13, 2025 at 6:33 AM CET, Antonio Hickey wrote:
Replacing all occurrences of `addr_of!(place)` with `&raw place`, and
all occurrences of `addr_of_mut!(place)` with `&raw mut place`.

Utilizing the new feature will allow us to reduce macro complexity, and
improve consistency with existing reference syntax as `&raw`, `&raw mut`
is very similar to `&`, `&mut` making it fit more naturally with other
existing code.

Depends on: Patch 1/3 0001-rust-enable-raw_ref_op-feature.patch
This information shouldn't be in the commit message. You can put it
below the `---` (that won't end up in the commit message). But since you
sent this as part of a series, you don't need to mention it.
Suggested-by: Benno Lossin <redacted>
Link: https://github.com/Rust-for-Linux/linux/issues/1148
Signed-off-by: Antonio Hickey <redacted>
---
 rust/kernel/block/mq/request.rs        |  4 ++--
 rust/kernel/faux.rs                    |  4 ++--
 rust/kernel/fs/file.rs                 |  2 +-
 rust/kernel/init.rs                    |  8 ++++----
 rust/kernel/init/macros.rs             | 28 +++++++++++++-------------
 rust/kernel/jump_label.rs              |  4 ++--
 rust/kernel/kunit.rs                   |  4 ++--
 rust/kernel/list.rs                    |  2 +-
 rust/kernel/list/impl_list_item_mod.rs |  6 +++---
 rust/kernel/net/phy.rs                 |  4 ++--
 rust/kernel/pci.rs                     |  4 ++--
 rust/kernel/platform.rs                |  4 +---
 rust/kernel/rbtree.rs                  | 22 ++++++++++----------
 rust/kernel/sync/arc.rs                |  2 +-
 rust/kernel/task.rs                    |  4 ++--
 rust/kernel/workqueue.rs               |  8 ++++----
 16 files changed, 54 insertions(+), 56 deletions(-)
[...]
quoted hunk
diff --git a/rust/kernel/jump_label.rs b/rust/kernel/jump_label.rs
index 4e974c768dbd..05d4564714c7 100644
--- a/rust/kernel/jump_label.rs
+++ b/rust/kernel/jump_label.rs
@@ -20,8 +20,8 @@
 #[macro_export]
 macro_rules! static_branch_unlikely {
     ($key:path, $keytyp:ty, $field:ident) => {{
-        let _key: *const $keytyp = ::core::ptr::addr_of!($key);
-        let _key: *const $crate::bindings::static_key_false = ::core::ptr::addr_of!((*_key).$field);
+        let _key: *const $keytyp = &raw $key;
This should be `&raw const $key`. I wrote that wrongly in the issue.
+        let _key: *const $crate::bindings::static_key_false = &raw (*_key).$field;
Same here.
quoted hunk
         let _key: *const $crate::bindings::static_key = _key.cast();
 
         #[cfg(not(CONFIG_JUMP_LABEL))]
diff --git a/rust/kernel/kunit.rs b/rust/kernel/kunit.rs
index 824da0e9738a..18357dd782ed 100644
--- a/rust/kernel/kunit.rs
+++ b/rust/kernel/kunit.rs
@@ -128,9 +128,9 @@ unsafe impl Sync for UnaryAssert {}
             unsafe {
                 $crate::bindings::__kunit_do_failed_assertion(
                     kunit_test,
-                    core::ptr::addr_of!(LOCATION.0),
+                    &raw LOCATION.0,
And here.
                     $crate::bindings::kunit_assert_type_KUNIT_ASSERTION,
-                    core::ptr::addr_of!(ASSERTION.0.assert),
+                    &raw ASSERTION.0.assert,
Lastly here as well.

---
Cheers,
Benno
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help