[PATCH v2 1/2] rust: clk: implement Send and Sync

Daniel Almeida
2025-09-10T17:29:12Z

From: Alice Ryhl <aliceryhl@google.com>

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. See e.g. [1] for the kind of workaround that drivers currently
need due to lacking this annotation.

Link: https://lore.kernel.org/rust-for-linux/20250812-tyr-v2-1-9e0f3dc9da95@collabora.com/ [1]
Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
---
rust/kernel/clk.rs | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/rust/kernel/clk.rs b/rust/kernel/clk.rs
index 1e6c8c42fb3a321951e275101848b35e1ae5c2a8..0a290202da69669d670ddad2b6762a1d5f1d912e 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.51.0