Re: [PATCH] rust: sync: fix safety comment for `Arc::from_raw`

From: Andreas Hindborg

Date: Wed Sep 23 2026 - 16:53:53 EST


Andreas Hindborg <a.hindborg@xxxxxxxxxx> writes:

> "Gary Guo" <gary@xxxxxxxxxxx> writes:
>
>> On Wed Sep 23, 2026 at 7:32 PM BST, Andreas Hindborg wrote:
>>> `Arc::from_raw` does not require `T: Send`. But if `Arc::from_raw` was
>>> executed on a different thread than `Arc::into_raw`, `T` must implement
>>> `Send` for the API to be sound. If this is not the case, ownership of `T`
>>> may be sent across a thread boundary even if `T: !Send`.
>>>
>>> Augment safety comment for `Arc::from_raw` to close this gap.
>>>
>>> Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
>>> ---
>>> rust/kernel/sync/arc.rs | 3 +++
>>> 1 file changed, 3 insertions(+)
>>>
>>> diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs
>>> index 8ae0fe6f19ec..06838ecf633c 100644
>>> --- a/rust/kernel/sync/arc.rs
>>> +++ b/rust/kernel/sync/arc.rs
>>> @@ -276,6 +276,9 @@ pub fn as_ptr(this: &Self) -> *const T {
>>> ///
>>> /// `ptr` must have been returned by a previous call to [`Arc::into_raw`]. Additionally, it
>>> /// must not be called more than once for each previous call to [`Arc::into_raw`].
>>> + ///
>>> + /// If [`Arc::into_raw`] was executed on a different thread than the one executing
>>> + /// [`Arc::from_raw`], `T` must implement [`Send`].
>>
>> This needs to be `Send + Sync`?
>
> Why does the `Arc` need to be `Sync` as well? We are transferring
> ownership, not a reference.

Ah, I get your point. The comment is wrong, I meant to say "`Arc<T>`
must implement `Send`". I did not mean to address `T`.

Best regards,
Andreas Hindborg