]> www.infradead.org Git - users/hch/misc.git/commitdiff
rust: platform: impl Send + Sync for platform::Device
authorDanilo Krummrich <dakr@kernel.org>
Tue, 18 Mar 2025 21:29:22 +0000 (22:29 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 18 Mar 2025 23:55:12 +0000 (16:55 -0700)
Commit 4d320e30ee04 ("rust: platform: fix unrestricted &mut
platform::Device") changed the definition of platform::Device and
discarded the implicitly derived Send and Sync traits.

This isn't required by upstream code yet, and hence did not cause any
issues. However, it is relied on by upcoming drivers, hence add it back
in.

Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Link: https://lore.kernel.org/r/20250318212940.137577-2-dakr@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
rust/kernel/platform.rs

index c77c9f2e9aea1f022b3cf4064ec7e03c889c0fcd..2811ca53d8b67d8fb1abc92f48259db424d95e1d 100644 (file)
@@ -233,3 +233,10 @@ impl AsRef<device::Device> for Device {
         unsafe { device::Device::as_ref(dev) }
     }
 }
+
+// SAFETY: A `Device` is always reference-counted and can be released from any thread.
+unsafe impl Send for Device {}
+
+// SAFETY: `Device` can be shared among threads because all methods of `Device`
+// (i.e. `Device<Normal>) are thread safe.
+unsafe impl Sync for Device {}