Skip to content

Commit

Permalink
Merge pull request Rust-for-Linux#344 from TheSven73/rust-for-linux-f…
Browse files Browse the repository at this point in the history
…ix-warnings

rust: add unsafe annotations in of.rs and types.rs
  • Loading branch information
ojeda committed Jun 4, 2021
2 parents c82b757 + c732624 commit bfe9ec6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions rust/kernel/of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ impl PointerWrapper for OfMatchTable {
}

unsafe fn from_pointer(p: *const c_types::c_void) -> Self {
// SAFETY: The passed pointer comes from a previous call to [`InnerTable::into_pointer()`].
Self(unsafe { InnerTable::from_pointer(p) })
}
}
6 changes: 5 additions & 1 deletion rust/kernel/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ impl<T> PointerWrapper for Box<T> {
}

unsafe fn from_pointer(ptr: *const c_types::c_void) -> Self {
// SAFETY: The passed pointer comes from a previous call to [`Self::into_pointer()`].
unsafe { Box::from_raw(ptr as _) }
}
}
Expand All @@ -64,6 +65,7 @@ impl<T: RefCounted> PointerWrapper for Ref<T> {
}

unsafe fn from_pointer(ptr: *const c_types::c_void) -> Self {
// SAFETY: The passed pointer comes from a previous call to [`Self::into_pointer()`].
unsafe { Ref::from_raw(ptr as _) }
}
}
Expand All @@ -74,6 +76,7 @@ impl<T> PointerWrapper for Arc<T> {
}

unsafe fn from_pointer(ptr: *const c_types::c_void) -> Self {
// SAFETY: The passed pointer comes from a previous call to [`Self::into_pointer()`].
unsafe { Arc::from_raw(ptr as _) }
}
}
Expand All @@ -87,7 +90,8 @@ impl<T: PointerWrapper + Deref> PointerWrapper for Pin<T> {
}

unsafe fn from_pointer(p: *const c_types::c_void) -> Self {
// TODO: Review: SAFETY: The object was originally pinned.
// SAFETY: The object was originally pinned.
// The passed pointer comes from a previous call to `inner::into_pointer()`.
unsafe { Pin::new_unchecked(T::from_pointer(p)) }
}
}
Expand Down

0 comments on commit bfe9ec6

Please sign in to comment.