diff options
author | 2025-01-03 17:46:03 +0100 | |
---|---|---|
committer | 2025-01-07 11:31:45 +0100 | |
commit | e1a51c2bf4b3b20868a0e6e9520b11639bd363f1 (patch) | |
tree | 2a1be8a3b07303bd8432fabb28e6e0ee09fd8661 /rust/kernel/pci.rs | |
parent | rust: io: move module entry to its correct location (diff) | |
download | wireguard-linux-e1a51c2bf4b3b20868a0e6e9520b11639bd363f1.tar.xz wireguard-linux-e1a51c2bf4b3b20868a0e6e9520b11639bd363f1.zip |
rust: driver: address soundness issue in `RegistrationOps`
The `RegistrationOps` trait holds some obligations to the caller and
implementers. While being documented, the trait and the corresponding
functions haven't been marked as unsafe.
Hence, markt the trait and functions unsafe and add the corresponding
safety comments.
This patch does not include any fuctional changes.
Reported-by: Gary Guo <gary@garyguo.net>
Closes: https://lore.kernel.org/rust-for-linux/20241224195821.3b43302b.gary@garyguo.net/
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
Link: https://lore.kernel.org/r/20250103164655.96590-4-dakr@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'rust/kernel/pci.rs')
-rw-r--r-- | rust/kernel/pci.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index d5e7f0b15303..4c98b5b9aa1e 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -23,10 +23,12 @@ use kernel::prelude::*; /// An adapter for the registration of PCI drivers. pub struct Adapter<T: Driver>(T); -impl<T: Driver + 'static> driver::RegistrationOps for Adapter<T> { +// SAFETY: A call to `unregister` for a given instance of `RegType` is guaranteed to be valid if +// a preceding call to `register` has been successful. +unsafe impl<T: Driver + 'static> driver::RegistrationOps for Adapter<T> { type RegType = bindings::pci_driver; - fn register( + unsafe fn register( pdrv: &Opaque<Self::RegType>, name: &'static CStr, module: &'static ThisModule, @@ -45,7 +47,7 @@ impl<T: Driver + 'static> driver::RegistrationOps for Adapter<T> { }) } - fn unregister(pdrv: &Opaque<Self::RegType>) { + unsafe fn unregister(pdrv: &Opaque<Self::RegType>) { // SAFETY: `pdrv` is guaranteed to be a valid `RegType`. unsafe { bindings::pci_unregister_driver(pdrv.get()) } } |