rust: Update PCI binding safety comments and add inline compiler hint

Update the safety comments to be consistent with other safety comments
in the PCI bindings. Also add an inline compiler hint.

Suggested-by: Danilo Krummrich <dakr@kernel.org>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Krzysztof Wilczyński <kwilczynski@kernel.org>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Alex Gaynor <alex.gaynor@gmail.com>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Gary Guo <gary@garyguo.net>
Cc: Björn Roy Baron <bjorn3_gh@protonmail.com>
Cc: Benno Lossin <lossin@kernel.org>
Cc: Andreas Hindborg <a.hindborg@kernel.org>
Cc: Alice Ryhl <aliceryhl@google.com>
Cc: Trevor Gross <tmgross@umich.edu>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Rafael J. Wysocki <rafael@kernel.org>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Alexandre Courbot <acourbot@nvidia.com>
Cc: linux-pci@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Alistair Popple <apopple@nvidia.com>
Link: https://lore.kernel.org/r/20250730013417.640593-1-apopple@nvidia.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
This commit is contained in:
Alistair Popple 2025-07-30 11:34:16 +10:00 committed by Danilo Krummrich
parent b0d73ad126
commit cd58b0b11d

View File

@ -388,14 +388,18 @@ impl<Ctx: device::DeviceContext> Device<Ctx> {
impl Device {
/// Returns the PCI vendor ID.
#[inline]
pub fn vendor_id(&self) -> u16 {
// SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`.
// SAFETY: By its type invariant `self.as_raw` is always a valid pointer to a
// `struct pci_dev`.
unsafe { (*self.as_raw()).vendor }
}
/// Returns the PCI device ID.
#[inline]
pub fn device_id(&self) -> u16 {
// SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`.
// SAFETY: By its type invariant `self.as_raw` is always a valid pointer to a
// `struct pci_dev`.
unsafe { (*self.as_raw()).device }
}