[PATCH v5 1/3] rust: clk: implement Send and Sync
From: Alice Ryhl
Date: Mon Feb 23 2026 - 05:16:12 EST
These traits are required for drivers to embed the Clk type in their own
data structures because driver data structures are usually required to
be Send. Since the Clk type is thread-safe, implement the relevant
traits.
Reviewed-by: Daniel Almeida <daniel.almeida@xxxxxxxxxxxxx>
Reviewed-by: Danilo Krummrich <dakr@xxxxxxxxxx>
Acked-by: Viresh Kumar <viresh.kumar@xxxxxxxxxx>
Reviewed-by: Boqun Feng <boqun.feng@xxxxxxxxx>
Reviewed-by: Gary Guo <gary@xxxxxxxxxxx>
Signed-off-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
---
rust/kernel/clk.rs | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/rust/kernel/clk.rs b/rust/kernel/clk.rs
index 4059aff34d096264bc7f3c8bfcb39eb3f42725be..7abbd0767d8cff9f2561d1783a9a1d774a96d1fc 100644
--- a/rust/kernel/clk.rs
+++ b/rust/kernel/clk.rs
@@ -128,6 +128,13 @@ mod common_clk {
#[repr(transparent)]
pub struct Clk(*mut bindings::clk);
+ // SAFETY: It is safe to call `clk_put` on another thread than where `clk_get` was called.
+ unsafe impl Send for Clk {}
+
+ // SAFETY: It is safe to call any combination of the `&self` methods in parallel, as the
+ // methods are synchronized internally.
+ unsafe impl Sync for Clk {}
+
impl Clk {
/// Gets [`Clk`] corresponding to a [`Device`] and a connection id.
///
--
2.53.0.345.g96ddfc5eaa-goog