Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: auxiliary: consider auxiliary devices always have a parent

An auxiliary device is guaranteed to always have a parent device (both
in C and Rust), hence don't return an Option<&auxiliary::Device> in
auxiliary::Device::parent().

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

+6 -5
+1 -1
drivers/gpu/drm/nova/file.rs
··· 28 28 _file: &drm::File<File>, 29 29 ) -> Result<u32> { 30 30 let adev = &dev.adev; 31 - let parent = adev.parent().ok_or(ENOENT)?; 31 + let parent = adev.parent(); 32 32 let pdev: &pci::Device = parent.try_into()?; 33 33 34 34 let value = match getparam.param as u32 {
+4 -3
rust/kernel/auxiliary.rs
··· 215 215 unsafe { (*self.as_raw()).id } 216 216 } 217 217 218 - /// Returns a reference to the parent [`device::Device`], if any. 219 - pub fn parent(&self) -> Option<&device::Device> { 220 - self.as_ref().parent() 218 + /// Returns a reference to the parent [`device::Device`]. 219 + pub fn parent(&self) -> &device::Device { 220 + // SAFETY: A `struct auxiliary_device` always has a parent. 221 + unsafe { self.as_ref().parent().unwrap_unchecked() } 221 222 } 222 223 } 223 224
+1 -1
samples/rust/rust_driver_auxiliary.rs
··· 68 68 69 69 impl ParentDriver { 70 70 fn connect(adev: &auxiliary::Device) -> Result<()> { 71 - let parent = adev.parent().ok_or(EINVAL)?; 71 + let parent = adev.parent(); 72 72 let pdev: &pci::Device = parent.try_into()?; 73 73 74 74 let vendor = pdev.vendor_id();