lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 16 Dec 2022 17:49:27 +0000
From:   Wei Liu <wei.liu@...nel.org>
To:     rust-for-linux@...r.kernel.org,
        Linux Kernel List <linux-kernel@...r.kernel.org>
Cc:     Wei Liu <wei.liu@...nel.org>, Miguel Ojeda <ojeda@...nel.org>,
        Alex Gaynor <alex.gaynor@...il.com>,
        Wedson Almeida Filho <wedsonaf@...il.com>,
        Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
        Björn Roy Baron <bjorn3_gh@...tonmail.com>
Subject: [PATCH] rust: kernel: drop repetition in offset_of macro

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@...nel.org>
---
Cc: Miguel Ojeda <ojeda@...nel.org>
Cc: Alex Gaynor <alex.gaynor@...il.com>
Cc: Wedson Almeida Filho <wedsonaf@...il.com>
Cc: Boqun Feng <boqun.feng@...il.com>
Cc: Gary Guo <gary@...yguo.net>
Cc: Björn Roy Baron <bjorn3_gh@...tonmail.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ