blob: b121762e7a3bdbac8535a1f9d1954d4a011908de [file]
From baae10961fc9741ffda4fd678283ca6c76fbbd98 Mon Sep 17 00:00:00 2001
From: Sasha Levin <sashal@kernel.org>
Date: Mon, 27 Apr 2026 01:21:13 +0200
Subject: rust: init: fix `clippy::undocumented_unsafe_blocks` warnings
From: Miguel Ojeda <ojeda@kernel.org>
The stable backport in commit acc105db0826 ("rust: pin-init:
add references to previously initialized fields") introduced some
`clippy::undocumented_unsafe_blocks` warnings [1], e.g.
error: unsafe block missing a safety comment
--> rust/kernel/init/macros.rs:1015:25
As well as:
--> rust/kernel/init/macros.rs:1243:45
--> rust/kernel/init/macros.rs:1286:22
--> rust/kernel/init/macros.rs:1374:45
After discussing it with Benno and Gary, we decided to clean the build
log by doing a minimal targeted stable commit.
Thus, depending on the case:
- Reorder the attributes so that the existing `// SAFETY:` comments
may be seen by Clippy.
- Add a placeholder `// SAFETY: TODO.` comment.
Cc: Benno Lossin <lossin@kernel.org>
Cc: Gary Guo <gary@garyguo.net>
Fixes: acc105db0826 ("rust: pin-init: add references to previously initialized fields")
Link: https://lore.kernel.org/stable/20260421111111.57059-1-ojeda@kernel.org/ [1]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
rust/kernel/init/macros.rs | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/rust/kernel/init/macros.rs b/rust/kernel/init/macros.rs
index e477e4de817bf..d6e27c5221155 100644
--- a/rust/kernel/init/macros.rs
+++ b/rust/kernel/init/macros.rs
@@ -1012,6 +1012,7 @@ macro_rules! __pin_data {
self,
slot: &'__slot mut $p_type,
) -> ::core::pin::Pin<&'__slot mut $p_type> {
+ // SAFETY: TODO.
unsafe { ::core::pin::Pin::new_unchecked(slot) }
}
)*
@@ -1235,11 +1236,11 @@ macro_rules! __init_internal {
// Unaligned fields will cause the compiler to emit E0793. We do not support
// unaligned fields since `Init::__init` requires an aligned pointer; the call to
// `ptr::write` below has the same requirement.
+ #[allow(unused_variables, unused_assignments)]
// SAFETY:
// - the project function does the correct field projection,
// - the field has been initialized,
// - the reference is only valid until the end of the initializer.
- #[allow(unused_variables, unused_assignments)]
let $field = $crate::macros::paste!(unsafe { $data.[< __project_ $field >](&mut (*$slot).$field) });
// Create the drop guard:
@@ -1278,11 +1279,11 @@ macro_rules! __init_internal {
// Unaligned fields will cause the compiler to emit E0793. We do not support
// unaligned fields since `Init::__init` requires an aligned pointer; the call to
// `ptr::write` below has the same requirement.
+ #[allow(unused_variables, unused_assignments)]
// SAFETY:
// - the field is not structurally pinned, since the line above must compile,
// - the field has been initialized,
// - the reference is only valid until the end of the initializer.
- #[allow(unused_variables, unused_assignments)]
let $field = unsafe { &mut (*$slot).$field };
// Create the drop guard:
@@ -1366,11 +1367,11 @@ macro_rules! __init_internal {
// Unaligned fields will cause the compiler to emit E0793. We do not support
// unaligned fields since `Init::__init` requires an aligned pointer; the call to
// `ptr::write` below has the same requirement.
+ #[allow(unused_variables, unused_assignments)]
// SAFETY:
// - the project function does the correct field projection,
// - the field has been initialized,
// - the reference is only valid until the end of the initializer.
- #[allow(unused_variables, unused_assignments)]
let $field = $crate::macros::paste!(unsafe { $data.[< __project_ $field >](&mut (*$slot).$field) });
// Create the drop guard:
--
2.53.0