From: Daniel Almeida Date: Tue, 29 Jul 2025 17:31:41 +0000 (-0300) Subject: rust: regulator: implement Send and Sync for Regulator X-Git-Tag: v6.18-rc1~166^2~18^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9a200cbdb54349909a42b45379e792e4b39dd223;p=thirdparty%2Flinux.git rust: regulator: implement Send and Sync for Regulator Sending a &Regulator to another thread is safe, as the regulator core will properly handle the locking for us. Additionally, there are no restrictions that prevents sending a Regulator to another thread. Given these two facts, implement Send and Sync. Signed-off-by: Daniel Almeida Link: https://patch.msgid.link/20250729-regulator-send-sync-v1-2-8bcbd546b940@collabora.com Reviewed-by: Alexandre Courbot Reviewed-by: Alice Ryhl Signed-off-by: Mark Brown --- diff --git a/rust/kernel/regulator.rs b/rust/kernel/regulator.rs index d56aa229e838c..704147e18bfc9 100644 --- a/rust/kernel/regulator.rs +++ b/rust/kernel/regulator.rs @@ -398,6 +398,14 @@ impl Drop for Regulator { } } +// SAFETY: It is safe to send a `Regulator` across threads. In particular, a +// Regulator can be dropped from any thread. +unsafe impl Send for Regulator {} + +// SAFETY: It is safe to send a &Regulator across threads because the C side +// handles its own locking. +unsafe impl Sync for Regulator {} + /// A voltage. /// /// This type represents a voltage value in microvolts.