Re: [PATCH v4 2/6] rust: pci: add sriov_get_totalvfs() helper
From: Alexandre Courbot
Date: Thu Jul 16 2026 - 11:03:27 EST
On Thu Jul 9, 2026 at 4:00 PM PDT, Danilo Krummrich wrote:
> On Thu Jul 9, 2026 at 5:02 PM CEST, Zhi Wang wrote:
>> + /// Returns the total number of VFs, or [`None`] if SR-IOV is not available.
>> + #[inline]
>> + pub fn sriov_get_totalvfs(&self) -> Option<NonZero<u16>> {
>> + // SAFETY: `self.as_raw()` is a valid pointer to a `struct pci_dev`.
>> + let total_vfs = unsafe { bindings::pci_sriov_get_totalvfs(self.as_raw()) };
>> +
>> + // CAST: The C function returns `unsigned int`, but the value originates
>> + // from TotalVFs/driver_max_VFs (which are defined as `u16`), so this cast
>> + // cannot truncate.
>> + NonZero::new(total_vfs as u16)
>> + }
>> }
>>
>> impl<'a> Device<device::Core<'a>> {
>
> It is not a problem yet, but sriov_get_totalvfs() should go into the
> Device<Core> impl above.
>
> Once we also have sriov_set_totalvfs() this would otherwise be a potential data
> race.
With the above addressed,
Reviewed-by: Alexandre Courbot <acourbot@xxxxxxxxxx>