rust: Update PCI binding safety comments and add inline compiler hint
PATCH v3 1/2 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.
---
Changes for v3:
- Updated capitalisation of SAFETY comments
--- rust/kernel/pci.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
rust/kernel/pci.rs +6 -2
@@ -371,14 +371,18 @@ fn as_raw(&self) -> *mut bindings::pci_dev {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 } }
Signature · 1 line
2.47.2
PATCH v3 2/2 rust: Add several miscellaneous PCI helpers
Add bindings to obtain a PCI device's resource start address, bus/ device function, revision ID and subsystem device and vendor IDs.
These will be used by the nova-core GPU driver which is currently in development.
---
Changes for v3:
- Fixed capitalisation of SAFETY comments.
- There was a long discussion about the SAFETY comments on v2 of the series[1]. I don't think anything actionable came of it so I haven't made any changes as a result of that discussion.
[1] - https://lore.kernel.org/rust-for-linux/[email protected]/
--- rust/helpers/pci.c | 10 ++++++++++ rust/kernel/pci.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+)
rust/helpers/pci.c +10 -0
@@ -12,6 +12,16 @@ void *rust_helper_pci_get_drvdata(struct pci_dev *pdev)return pci_get_drvdata (pdev); } +u16 rust_helper_pci_dev_id (struct pci_dev *dev) +{ +return PCI_DEVID (dev->bus->number, dev->devfn); +} + +resource_size_t rust_helper_pci_resource_start (struct pci_dev *pdev,int bar) +{ +return pci_resource_start (pdev, bar); +} +resource_size_t rust_helper_pci_resource_len (struct pci_dev *pdev,int bar) {return pci_resource_len (pdev, bar);
rust/kernel/pci.rs +44 -0
50 lines not on this page · raw message
Signature · 1 line
2.47.2
Quoted 2 lines · Alistair Popple
I think this list of Ccs is automated, given even the LKML is included, but the Cc: tag inside the commit message is not meant to be used to mention every maintainer/reviewer, i.e. it is normally used when you want to document that someone was contacted (i.e. for a particular reason, not in general).
Otherwise, all commits would have very long lists of Ccs and the value of the tag is diminished.
Cheers,
Miguel
Danilo Krummrich
maintainerQuoted 15 lines · Alistair Popple
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 <[email protected]>Cc Danilo Krummrich <[email protected]>Cc Bjorn Helgaas <[email protected]>Cc Krzysztof Wilczyński <[email protected]>Cc Miguel Ojeda <[email protected]>Cc Alex Gaynor <[email protected]>Cc Boqun Feng <[email protected]>Cc Gary Guo <[email protected]>Cc Björn Roy Baron <[email protected]>Cc Benno Lossin <[email protected]>Cc Andreas Hindborg <[email protected]>Cc Alice Ryhl <[email protected]>
Quoted 8 lines
Cc Trevor Gross <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Rafael J. Wysocki <[email protected]>Cc John Hubbard <[email protected]>Cc Alexandre Courbot <[email protected]>Signed-off-by Alistair Popple <[email protected]>
Applied to driver-core-testing, thanks!
Alistair, do you mind sending a follow-up patch to replace the raw bindings:resource_size_t return types on resource_start() and resource_len() with the Rust ResourceSize type?