rust: clk: implement Send and Sync
Subsystems (2)
Alice Ryhl
reviewerPATCH 1/1 rust: clk: implement Send and Sync
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.
---
I'm not sure if there was already sent a patch for this. I recall being told that one had been sent, but I could not find it. Maybe I mixed it up with the regulator change, so now I'm sending a change for clk.
--- rust/kernel/clk.rs | 7 +++++++ 1 file changed, 7 insertions(+)
rust/kernel/clk.rs +7 -0
@@ -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. ///
---
base-commit: 1b237f190eb3d36f52dffe07a40b5eb210280e00
change-id: 20250904-clk-send-sync-3cfa7f4e1ce2
Best regards,
Signature · 1 line
Alice Ryhl <[email protected]>
Quoted 7 lines · Alice Ryhl
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.
Signed-off-by Alice Ryhl <[email protected]>
Quoted 8 lines
---
I'm not sure if there was already sent a patch for this. I recall being told that one had been sent, but I could not find it. Maybe I mixed it up with the regulator change, so now I'm sending a change for clk.--- rust/kernel/clk.rs | 7 +++++++ 1 file changed, 7 insertions(+)
Signature · 1 line
viresh
Daniel Almeida
reviewerHi Alice, good catch, this is indeed missing.
Quoted 41 lines · Alice Ryhl
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.
Signed-off-by Alice Ryhl <[email protected]>---
I'm not sure if there was already sent a patch for this. I recall being told that one had been sent, but I could not find it. Maybe I mixed it up with the regulator change, so now I'm sending a change for clk.
---rust/kernel/clk.rs| 7 +++++++1 file changed, 7 insertions(+)rust/kernel/clk.rs +7
-1@@ -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. /// ---base-commit:
1b237f190eb3d36f52dffe07a40b5eb210280e00
change-id: 20250904-clk-send-sync-3cfa7f4e1ce2
Quoted 4 lines
Best regards,
Signature · 1 line
Alice Ryhl <[email protected]>
Can you base your change on top of [0]? Otherwise it will become stale rather quickly, as this introduces new types, i.e.: Clk<Unprepared>, Clk<Prepared> etc.
I will push out a new version today.
[0]: https://lore.kernel.org/rust-for-linux/[email protected]/
Alice Ryhl
reviewerQuoted 7 lines · Daniel Almeida
Can you base your change on top of [0]? Otherwise it will become stale rather quickly, as this introduces new types, i.e.: Clk<Unprepared>, Clk<Prepared> etc.
I will push out a new version today.
[0]: https://lore.kernel.org/rust-for-linux/[email protected]/
I would suggest the reverse. If your series is based on top of mine, then this patch can land today regardless of how long it takes to finish the clk refactor.
Alice
Quoted 12 lines · Alice Ryhl
Quoted 6 lines · Daniel Almeida
Can you base your change on top of [0]? Otherwise it will become stale rather quickly, as this introduces new types, i.e.: Clk<Unprepared>, Clk<Prepared> etc.
I will push out a new version today.
Quoted 8 lines
Quoted 1 line
[0]: https://lore.kernel.org/rust-for-linux/[email protected]/
I would suggest the reverse. If your series is based on top of mine, then this patch can land today regardless of how long it takes to finish the clk refactor.
Alice
True,
Ok then:
Quoted 7 lines · Alice Ryhl
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.
Signed-off-by Alice Ryhl <[email protected]>
Daniel Almeida
reviewerQuoted 43 lines · Alice Ryhl
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.
Signed-off-by Alice Ryhl <[email protected]>---
I'm not sure if there was already sent a patch for this. I recall being told that one had been sent, but I could not find it. Maybe I mixed it up with the regulator change, so now I'm sending a change for clk.
---rust/kernel/clk.rs| 7 +++++++1 file changed, 7 insertions(+)rust/kernel/clk.rs +7
-1@@ -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. /// ---base-commit:
1b237f190eb3d36f52dffe07a40b5eb210280e00
change-id: 20250904-clk-send-sync-3cfa7f4e1ce2
Quoted 5 lines
Best regards,
Signature · 1 line
Alice Ryhl <[email protected]>
I’ve included this on my series here [0], as it would otherwise conflict with the type-state work.
I did not see anyone against the type-state patch itself, so perhaps both can go together.
— Daniel
[0]: https://lore.kernel.org/rust-for-linux/[email protected]/T/#t