Skip to content

Commit f76af94

Browse files
committed
drm/asahi: object: Clippy fixes
Signed-off-by: Asahi Lina <[email protected]>
1 parent 9a61f8e commit f76af94

1 file changed

Lines changed: 13 additions & 19 deletions

File tree

drivers/gpu/drm/asahi/object.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ impl<'a, T: ?Sized> GpuPointer<'a, T> {
8383
/// Add an arbitrary offset to the pointer. This is not safe (from the GPU perspective), and
8484
/// should only be used via the `inner_ptr` macro to get pointers to inner fields, hence we mark
8585
/// it `unsafe` to discourage direct use.
86+
///
87+
/// # Safety
88+
/// Do not use directly, only via `inner_ptr`.
8689
// NOTE: The third argument is a type inference hack.
8790
pub(crate) unsafe fn offset<U>(&self, off: usize, _: *const U) -> GpuPointer<'a, U> {
8891
GpuPointer::<'a, U>(
@@ -157,6 +160,7 @@ pub(crate) struct GpuWeakPointer<T: ?Sized>(NonZeroU64, PhantomData<*const T>);
157160

158161
/// SAFETY: GPU weak pointers are always safe to share between threads.
159162
unsafe impl<T: ?Sized> Send for GpuWeakPointer<T> {}
163+
/// SAFETY: GPU weak pointers are always safe to share between threads.
160164
unsafe impl<T: ?Sized> Sync for GpuWeakPointer<T> {}
161165

162166
// Weak pointers can be copied/cloned regardless of their target type.
@@ -170,8 +174,11 @@ impl<T: ?Sized> Clone for GpuWeakPointer<T> {
170174

171175
impl<T: ?Sized> GpuWeakPointer<T> {
172176
/// Add an arbitrary offset to the pointer. This is not safe (from the GPU perspective), and
173-
/// should only be used via the `inner_ptr` macro to get pointers to inner fields, hence we mark
174-
/// it `unsafe` to discourage direct use.
177+
/// should only be used via the `inner_weak_ptr` macro to get pointers to inner fields, hence we
178+
/// mark it `unsafe` to discourage direct use.
179+
///
180+
/// # Safety
181+
/// Do not use directly, only via `inner_weak_ptr`.
175182
// NOTE: The third argument is a type inference hack.
176183
pub(crate) unsafe fn offset<U>(&self, off: usize, _: *const U) -> GpuWeakPointer<U> {
177184
GpuWeakPointer::<U>(
@@ -182,6 +189,10 @@ impl<T: ?Sized> GpuWeakPointer<T> {
182189

183190
/// Upgrade a weak pointer into a strong pointer. This is not considered safe from the GPU
184191
/// perspective.
192+
///
193+
/// # Safety
194+
/// The caller must ensure tht the data pointed to lives in the GPU at least as long as the
195+
/// returned lifetime.
185196
pub(crate) unsafe fn upgrade<'a>(&self) -> GpuPointer<'a, T> {
186197
GpuPointer(self.0, PhantomData)
187198
}
@@ -634,23 +645,6 @@ pub(crate) struct GpuArray<T, U: Allocation<T>> {
634645
array: GpuOnlyArray<T, U>,
635646
}
636647

637-
/* Not used yet
638-
impl<T: Copy, U: Allocation<T>> GpuArray<T, U> {
639-
/// Allocate a new GPU array, copying the contents from a slice.
640-
pub(crate) fn new(alloc: U, data: &[T]) -> Result<GpuArray<T, U>> {
641-
let p = alloc.ptr().ok_or(EINVAL)?.as_ptr();
642-
let inner = GpuOnlyArray::new(alloc, data.len())?;
643-
// SAFETY: `p` is valid per the Allocation type invariant, and GpuOnlyArray guarantees
644-
// that its size is at least as large as `data.len()`.
645-
unsafe { ptr::copy(data.as_ptr(), p, data.len()) };
646-
Ok(Self {
647-
raw: p,
648-
array: inner,
649-
})
650-
}
651-
}
652-
*/
653-
654648
impl<T: Default, U: Allocation<T>> GpuArray<T, U> {
655649
/// Allocate a new GPU array, initializing each element to its default.
656650
pub(crate) fn empty(alloc: U, count: usize) -> Result<GpuArray<T, U>> {

0 commit comments

Comments
 (0)