[PATCH v1 1/7] rust: sync: completion: add wait_for_completion_timeout()
From: Joel Fernandes
Date: Fri May 01 2026 - 16:59:07 EST
Add a timeout variant of wait_for_completion() that wraps the C
function wait_for_completion_timeout(). Returns true if the task
completed before the timeout, else false.
The timeout is specified in jiffies. This is needed by drivers
that perform interrupt self-tests during probe, where an indefinite
wait would hang the system if the interrupt path is broken.
Signed-off-by: Joel Fernandes <joelagnelf@xxxxxxxxxx>
---
rust/kernel/sync/completion.rs | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/rust/kernel/sync/completion.rs b/rust/kernel/sync/completion.rs
index c50012a940a3..a2f46862365e 100644
--- a/rust/kernel/sync/completion.rs
+++ b/rust/kernel/sync/completion.rs
@@ -6,7 +6,12 @@
//!
//! C header: [`include/linux/completion.h`](srctree/include/linux/completion.h)
-use crate::{bindings, prelude::*, types::Opaque};
+use crate::{
+ bindings,
+ prelude::*,
+ time::Jiffies,
+ types::Opaque, //
+};
/// Synchronization primitive to signal when a certain task has been completed.
///
@@ -109,4 +114,15 @@ pub fn wait_for_completion(&self) {
// SAFETY: `self.as_raw()` is a pointer to a valid `struct completion`.
unsafe { bindings::wait_for_completion(self.as_raw()) };
}
+
+ /// Wait for completion of a task with a timeout.
+ ///
+ /// This method waits for the completion of a task; it is not interruptible but has a timeout.
+ /// Returns `true` if the task completed before the timeout, `false` if the timeout elapsed.
+ ///
+ /// The timeout is specified in jiffies. See also [`Completion::complete_all`].
+ pub fn wait_for_completion_timeout(&self, timeout: Jiffies) -> bool {
+ // SAFETY: `self.as_raw()` is a pointer to a valid `struct completion`.
+ unsafe { bindings::wait_for_completion_timeout(self.as_raw(), timeout) != 0 }
+ }
}
base-commit: 610e892bdb57043c7769982c2bff0260b6007b75
--
2.34.1