2
0
mirror of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git synced 2025-09-04 20:19:47 +08:00
linux/samples/rust
Danilo Krummrich 4d320e30ee rust: platform: fix unrestricted &mut platform::Device
As by now, platform::Device is implemented as:

	#[derive(Clone)]
	pub struct Device(ARef<device::Device>);

This may be convenient, but has the implication that drivers can call
device methods that require a mutable reference concurrently at any
point of time.

Instead define platform::Device as

	pub struct Device<Ctx: DeviceContext = Normal>(
		Opaque<bindings::platform_dev>,
		PhantomData<Ctx>,
	);

and manually implement the AlwaysRefCounted trait.

With this we can implement methods that should only be called from
bus callbacks (such as probe()) for platform::Device<Core>. Consequently,
we make this type accessible in bus callbacks only.

Arbitrary references taken by the driver are still of type
ARef<platform::Device> and hence don't provide access to methods that are
reserved for bus callbacks.

Fixes: 683a63befc ("rust: platform: add basic platform device / driver abstractions")
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Acked-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20250314160932.100165-5-dakr@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-03-17 08:04:25 +01:00
..
hostprogs
Kconfig rust/kernel: Add faux device bindings 2025-02-13 16:58:58 +01:00
Makefile rust/kernel: Add faux device bindings 2025-02-13 16:58:58 +01:00
rust_driver_faux.rs rust/faux: Add missing parent argument to Registration::new() 2025-02-27 18:03:17 -08:00
rust_driver_pci.rs rust: pci: fix unrestricted &mut pci::Device 2025-03-17 08:04:25 +01:00
rust_driver_platform.rs rust: platform: fix unrestricted &mut platform::Device 2025-03-17 08:04:25 +01:00
rust_minimal.rs rust: treewide: switch to the kernel Vec type 2024-10-15 23:10:32 +02:00
rust_misc_device.rs samples: rust_misc_device: Provide an example C program to exercise functionality 2024-12-16 16:12:56 +01:00
rust_print_events.c rust: samples: add tracepoint to Rust sample 2024-11-04 16:21:44 -05:00
rust_print_main.rs rust: use derive(CoercePointee) on rustc >= 1.84.0 2025-01-13 23:45:30 +01:00