Thank you for your contribution! Sashiko AI review found 1 potential issue(s) 
to consider:
- [Low] Missing `#[inline]` annotations on small abstraction functions in 
`ForeignOwnable for ARef<T>`.
--

commit 4199b74db0ae4068188998ff9452d6df8acb7816
Author: Danilo Krummrich <[email protected]>

rust: types: implement ForeignOwnable for ARef<T>

Implement ForeignOwnable for ARef<T>, making it possible for C code to
own an ARef<T>.

> diff --git a/rust/kernel/sync/aref.rs b/rust/kernel/sync/aref.rs
> --- a/rust/kernel/sync/aref.rs
> +++ b/rust/kernel/sync/aref.rs

[ ... ]

> +unsafe impl<T: AlwaysRefCounted + 'static> ForeignOwnable for ARef<T> {
> +    const FOREIGN_ALIGN: usize = core::mem::align_of::<T>();
> +
> +    type Borrowed<'a> = &'a T;
> +    type BorrowedMut<'a> = &'a T;
> +
> +    fn into_foreign(self) -> *mut c_void {
> +        ARef::into_raw(self).as_ptr().cast()
> +    }
> +
> +    unsafe fn from_foreign(ptr: *mut c_void) -> Self {
> +        // SAFETY: The safety requirements of this function ensure that 
> `ptr` comes from a previous
> +        // call to `Self::into_foreign`.
> +        let ptr = unsafe { NonNull::new_unchecked(ptr.cast()) };
> +
> +        // SAFETY: `ptr` came from `into_foreign`, which consumed an `ARef` 
> without decrementing
> +        // the refcount, so we can transfer the ownership to the new `ARef`.
> +        unsafe { ARef::from_raw(ptr) }
> +    }

[Severity: Low]
This isn't a bug, but should into_foreign() and from_foreign() be annotated 
with #[inline]? 

Since aref.rs is a core abstraction, the Rust coding guidelines suggest adding 
the inline annotation to small or forwarding functions to help with cross-crate 
inlining optimizations. Would it make sense to add this to borrow() and 
borrow_mut() in this block as well?

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=1

Reply via email to