Skip to contentSkip to conversation

rust: auxiliary: fix false positive warning for missing a safety comment

PATCH In review Danilo Krummrich 3 participants 4 messages Nov 3, 2025 – Nov 5, 2025

Subsystems (2)
lore
Share & tools
lore

Danilo Krummrich

author maintainer
#0 lore raw

PATCH 1/1 rust: auxiliary: fix false positive warning for missing a safety comment

Some older (yet supported) versions of clippy throw a false positive warning for missing a safety comment when the safety comment is on a multiline statement.

warning: unsafe block missing a safety comment
--> rust/kernel/auxiliary.rs:351:22

    |
351 |                 Self(unsafe { NonNull::new_unchecked(adev) }),
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |

= help: consider adding a safety comment on the preceding line
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#undocumented_unsafe_blocks
= note: requested on the command line with -W clippy::undocumented-unsafe-blocks

warning: 1 warning emitted

Fix this by placing the safety comment right on top of the same line introducing the unsafe block.

Fixes e4e679c8608e ("rust: auxiliary: unregister on parent device unbind")
---
 rust/kernel/auxiliary.rs | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
rust/kernel/auxiliary.rs +2 -3
index cc67fa5ddde3..618eeeec2bd0 100644
@@ -341,13 +341,12 @@ pub fn new<'a>(
                 return Err(Error::from_errno(ret));
             }
 
-            // SAFETY: `adev` is guaranteed to be non-null, since the `KBox` was allocated
-            // successfully.
-            //
             // INVARIANT: The device will remain registered until `auxiliary_device_delete()` is
             // called, which happens in `Self::drop()`.
             Ok(Devres::new(
                 parent,
+                // SAFETY: `adev` is guaranteed to be non-null, since the `KBox` was allocated
+                // successfully.
                 Self(unsafe { NonNull::new_unchecked(adev) }),
             ))
         })
Signature · 1 line
2.51.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 49 lines · Danilo Krummrich

Some older (yet supported) versions of clippy throw a false positive warning for missing a safety comment when the safety comment is on a multiline statement.

warning: unsafe block missing a safety comment
--> rust/kernel/auxiliary.rs:351:22

    |
351 |                 Self(unsafe { NonNull::new_unchecked(adev) }),
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |

= help: consider adding a safety comment on the preceding line
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#undocumented_unsafe_blocks
= note: requested on the command line with -W clippy::undocumented-unsafe-blocks

warning: 1 warning emitted

Fix this by placing the safety comment right on top of the same line introducing the unsafe block.

Fixes e4e679c8608e ("rust: auxiliary: unregister on parent device unbind")
---
 rust/kernel/auxiliary.rs | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
rust/kernel/auxiliary.rs +2 -3
index cc67fa5ddde3..618eeeec2bd0 100644
@@ -341,13 +341,12 @@ pub fn new<'a>(
                 return Err(Error::from_errno(ret));
             }
 
-            // SAFETY: `adev` is guaranteed to be non-null, since the `KBox` was allocated
-            // successfully.
-            //
             // INVARIANT: The device will remain registered until `auxiliary_device_delete()` is
             // called, which happens in `Self::drop()`.
             Ok(Devres::new(
                 parent,
+                // SAFETY: `adev` is guaranteed to be non-null, since the `KBox` was allocated
+                // successfully.
                 Self(unsafe { NonNull::new_unchecked(adev) }),
             ))
         })
Signature · 1 line
2.51.0
reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Danilo Krummrich
Quoted 14 lines · Danilo Krummrich

Some older (yet supported) versions of clippy throw a false positive warning for missing a safety comment when the safety comment is on a multiline statement.

warning: unsafe block missing a safety comment
--> rust/kernel/auxiliary.rs:351:22

    |
351 |                 Self(unsafe { NonNull::new_unchecked(adev) }),
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |

= help: consider adding a safety comment on the preceding line
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#undocumented_unsafe_blocks
= note: requested on the command line with -W clippy::undocumented-unsafe-blocks

Quoted 7 lines

warning: 1 warning emitted

Fix this by placing the safety comment right on top of the same line introducing the unsafe block.

Fixes e4e679c8608e ("rust: auxiliary: unregister on parent device unbind")
author maintainer
#3 lore raw
In reply to Danilo Krummrich
Quoted 14 lines · Danilo Krummrich

Some older (yet supported) versions of clippy throw a false positive warning for missing a safety comment when the safety comment is on a multiline statement.

warning: unsafe block missing a safety comment
--> rust/kernel/auxiliary.rs:351:22

    |
351 |                 Self(unsafe { NonNull::new_unchecked(adev) }),
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |

= help: consider adding a safety comment on the preceding line
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#undocumented_unsafe_blocks
= note: requested on the command line with -W clippy::undocumented-unsafe-blocks

Quoted 7 lines

warning: 1 warning emitted

Fix this by placing the safety comment right on top of the same line introducing the unsafe block.

Fixes e4e679c8608e ("rust: auxiliary: unregister on parent device unbind")

Applied to driver-core-testing, thanks!