Re: [PATCH v2 3/4] rust: completion: add complete()

From: Gary Guo

Date: Thu Jul 02 2026 - 10:49:44 EST


On Sat Jun 20, 2026 at 10:48 AM BST, Onur Özkan wrote:
> On Sat, 20 Jun 2026 10:45:47 +0200
> Maurice Hieronymus <mhi@xxxxxxxxxxx> wrote:
>
>> The initial completion abstraction only added complete_all() and
>> wait_for_completion(). complete_all() marks the completion permanently
>> done, which makes a single Completion unsuitable for signalling the same
>> event repeatedly: once complete_all() has run, every subsequent
>> wait_for_completion() returns immediately without waiting.
>>
>> Add complete(), which wakes a single waiter and increments the internal
>> counter by one. Paired one-to-one with wait_for_completion(), it allows
>> the same completion to be reused across multiple cycles, e.g. to wait for
>> consecutive DMA transfers to finish.
>>
>> Signed-off-by: Maurice Hieronymus <mhi@xxxxxxxxxxx>
>> ---
>> rust/kernel/sync/completion.rs | 11 +++++++++++
>> 1 file changed, 11 insertions(+)
>>
>> diff --git a/rust/kernel/sync/completion.rs b/rust/kernel/sync/completion.rs
>> index 35ff049ff078..a54361b53644 100644
>> --- a/rust/kernel/sync/completion.rs
>> +++ b/rust/kernel/sync/completion.rs
>> @@ -90,6 +90,17 @@ fn as_raw(&self) -> *mut bindings::completion {
>> self.inner.get()
>> }
>>
>> + /// Signal a single task waiting on this completion.
>> + ///
>> + /// This method wakes up a single task waiting on this completion.
>> + /// If no task is currently waiting, the next
>> + /// [`Completion::wait_for_completion`] returns immediately.
>> + #[inline]
>> + pub fn complete(&self) {
>> + // SAFETY: `self.as_raw()` is a pointer to a valid `struct completion`.
>
> I think the safety comment is a bit weak here. It would be nice to add why
> self.as_raw() is guaranteed to be a valid pointer.

I don't think that's needed. Saying `self.as_raw()` is valid is a sufficient
justification.

Best,
Gary