rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rust: kernel: drop repetition in offset_of macro
@ 2022-12-16 17:49 Wei Liu
  2022-12-16 18:26 ` Wedson Almeida Filho
  0 siblings, 1 reply; 7+ messages in thread
From: Wei Liu @ 2022-12-16 17:49 UTC (permalink / raw)
  To: rust-for-linux, Linux Kernel List
  Cc: Wei Liu, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho,
	Boqun Feng, Gary Guo, Björn Roy Baron

It doesn't make sense to allow multiple fields to be specified in
offset_of.

No functional change.

Signed-off-by: Wei Liu <wei.liu@kernel.org>
---
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Alex Gaynor <alex.gaynor@gmail.com>
Cc: Wedson Almeida Filho <wedsonaf@gmail.com>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Gary Guo <gary@garyguo.net>
Cc: Björn Roy Baron <bjorn3_gh@protonmail.com>
---
 rust/kernel/lib.rs | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
index 6a322effa60c..2f3601e4e27e 100644
--- a/rust/kernel/lib.rs
+++ b/rust/kernel/lib.rs
@@ -208,7 +208,7 @@ impl<'a> Drop for KParamGuard<'a> {
 /// ```
 #[macro_export]
 macro_rules! offset_of {
-    ($type:ty, $($f:tt)*) => {{
+    ($type:ty, $f:tt) => {{
         let tmp = core::mem::MaybeUninit::<$type>::uninit();
         let outer = tmp.as_ptr();
         // To avoid warnings when nesting `unsafe` blocks.
@@ -216,12 +216,14 @@ macro_rules! offset_of {
         // SAFETY: The pointer is valid and aligned, just not initialised; `addr_of` ensures that
         // we don't actually read from `outer` (which would be UB) nor create an intermediate
         // reference.
-        let inner = unsafe { core::ptr::addr_of!((*outer).$($f)*) } as *const u8;
+        let inner = unsafe { core::ptr::addr_of!((*outer).$f) } as *const u8;
         // To avoid warnings when nesting `unsafe` blocks.
         #[allow(unused_unsafe)]
         // SAFETY: The two pointers are within the same allocation block.
-        unsafe { inner.offset_from(outer as *const u8) }
-    }}
+        unsafe {
+            inner.offset_from(outer as *const u8)
+        }
+    }};
 }
 
 /// Produces a pointer to an object from a pointer to one of its fields.
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-12-16 23:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-16 17:49 [PATCH] rust: kernel: drop repetition in offset_of macro Wei Liu
2022-12-16 18:26 ` Wedson Almeida Filho
2022-12-16 22:15   ` Boqun Feng
2022-12-16 23:30     ` Wei Liu
2022-12-16 23:57       ` Miguel Ojeda
2022-12-16 23:08   ` Wei Liu
2022-12-16 23:15   ` Wei Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).