From: Christopher Joshy <christopherjoshy4@gmail.com>
To: ojeda@kernel.org
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
Christopher Joshy <christopherjoshy4@gmail.com>
Subject: [[PATCH]] rust: kernel: add SAFETY comments in aref doc example
Date: Sun, 12 Jul 2026 12:35:17 +0000 [thread overview]
Message-ID: <20260712123517.392-1-christopherjoshy4@gmail.com> (raw)
Replace TODO safety comments with proper explanations in the
`ARef::into_raw` doc example.
For the `unsafe impl AlwaysRefCounted`, explain that the empty
implementation is trivially sound since `Empty` has no data.
For the `ARef::from_raw` call, explain that the pointer is valid
because it is derived from a valid reference.
Link: https://github.com/Rust-for-Linux/linux/issues/351
Signed-off-by: Christopher Joshy <christopherjoshy4@gmail.com>
---
rust/kernel/sync/aref.rs | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/rust/kernel/sync/aref.rs b/rust/kernel/sync/aref.rs
index b721b2e00..932343799 100644
--- a/rust/kernel/sync/aref.rs
+++ b/rust/kernel/sync/aref.rs
@@ -124,7 +124,8 @@ pub unsafe fn from_raw(ptr: NonNull<T>) -> Self {
///
/// struct Empty {}
///
- /// # // SAFETY: TODO.
+ /// # // SAFETY: `Empty` has no data, so `inc_ref` and `dec_ref` being no-ops is trivially
+ /// # // sound.
/// unsafe impl AlwaysRefCounted for Empty {
/// fn inc_ref(&self) {}
/// unsafe fn dec_ref(_obj: NonNull<Self>) {}
@@ -132,7 +133,8 @@ pub unsafe fn from_raw(ptr: NonNull<T>) -> Self {
///
/// let mut data = Empty {};
/// let ptr = NonNull::<Empty>::new(&mut data).unwrap();
- /// # // SAFETY: TODO.
+ /// # // SAFETY: `ptr` is derived from a valid reference and is therefore non-null, properly
+ /// # // aligned, and points to a valid `Empty` instance.
/// let data_ref: ARef<Empty> = unsafe { ARef::from_raw(ptr) };
/// let raw_ptr: NonNull<Empty> = ARef::into_raw(data_ref);
///
--
2.43.0
next reply other threads:[~2026-07-12 12:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-12 12:35 Christopher Joshy [this message]
2026-07-12 12:42 ` [[PATCH]] rust: kernel: add SAFETY comments in aref doc example Miguel Ojeda
2026-07-12 15:30 ` [PATCH v2] " christopherjoshy
2026-07-12 15:49 ` [PATCH v3] " christopherjoshy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260712123517.392-1-christopherjoshy4@gmail.com \
--to=christopherjoshy4@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox