From: Oliver Mangold <[email protected]> SAFETY comment in rustdoc example was just 'TODO'. Fixed.
Link: https://github.com/Rust-for-Linux/linux/issues/351 Signed-off-by: Oliver Mangold <[email protected]> Reviewed-by: Daniel Almeida <[email protected]> Assisted-by: LLM Co-developed-by: Andreas Hindborg <[email protected]> Signed-off-by: Andreas Hindborg <[email protected]> --- rust/kernel/sync/aref.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/rust/kernel/sync/aref.rs b/rust/kernel/sync/aref.rs index 215e7eb139fa..ae76bd9b6c1c 100644 --- a/rust/kernel/sync/aref.rs +++ b/rust/kernel/sync/aref.rs @@ -147,7 +147,10 @@ pub unsafe fn from_raw(ptr: NonNull<T>) -> Self { /// /// struct Empty {} /// - /// # // SAFETY: TODO. + /// // SAFETY: The `RefCounted` implementation for `Empty` does not count references, and + /// // `dec_ref` never frees the underlying object, so a decrement cannot invalidate it. The + /// // object instead lives as long as the `Empty` value itself, so creators of `ARef<Empty>` + /// // must guarantee that the value outlives every `ARef` derived from it (as done below). /// unsafe impl RefCounted for Empty { /// fn inc_ref(&self) {} /// unsafe fn dec_ref(_obj: NonNull<Self>) {} @@ -155,7 +158,9 @@ pub unsafe fn from_raw(ptr: NonNull<T>) -> Self { /// /// let mut data = Empty {}; /// let ptr = NonNull::<Empty>::new(&mut data).unwrap(); - /// # // SAFETY: TODO. + /// // SAFETY: As the refcount operations of `Empty` are no-ops, we can treat `ptr` as owning + /// // an increment on the refcount. `data` outlives the created `ARef`, upholding the + /// // liveness guarantee required by the `RefCounted` implementation above. /// let data_ref: ARef<Empty> = unsafe { ARef::from_raw(ptr) }; /// let raw_ptr: NonNull<Empty> = ARef::into_raw(data_ref); /// -- 2.51.2
