Skip to content

Commit bfe9ec6

Browse files
authored
Merge pull request #344 from TheSven73/rust-for-linux-fix-warnings
rust: add unsafe annotations in of.rs and types.rs
2 parents c82b757 + c732624 commit bfe9ec6

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

rust/kernel/of.rs

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ impl PointerWrapper for OfMatchTable {
6969
}
7070

7171
unsafe fn from_pointer(p: *const c_types::c_void) -> Self {
72+
// SAFETY: The passed pointer comes from a previous call to [`InnerTable::into_pointer()`].
7273
Self(unsafe { InnerTable::from_pointer(p) })
7374
}
7475
}

rust/kernel/types.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ impl<T> PointerWrapper for Box<T> {
5454
}
5555

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

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

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

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

0 commit comments

Comments
 (0)