[PATCH v3 1/3] rust: clk: implement Send and Sync

Alice Ryhl aliceryhl at google.com
Thu Dec 18 05:27:40 PST 2025


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 at collabora.com>
Reviewed-by: Danilo Krummrich <dakr at kernel.org>
Acked-by: Viresh Kumar <viresh.kumar at linaro.org>
Reviewed-by: Boqun Feng <boqun.feng at gmail.com>
Signed-off-by: Alice Ryhl <aliceryhl at google.com>
---
 rust/kernel/clk.rs | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/rust/kernel/clk.rs b/rust/kernel/clk.rs
index c1cfaeaa36a22be2e3180b1e9142bb608ab276ea..d192fbd97861212d738d24510eebcd99c9177f2c 100644
--- a/rust/kernel/clk.rs
+++ b/rust/kernel/clk.rs
@@ -129,6 +129,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.52.0.351.gbe84eed79e-goog




More information about the linux-riscv mailing list