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: pci: implement TryInto<IrqRequest<'a>> for IrqVector<'a>

Implement TryInto<IrqRequest<'a>> for IrqVector<'a> to directly convert
a pci::IrqVector into a generic IrqRequest, instead of taking the
indirection via an unrelated pci::Device method.

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Joel Fernandes <joelagnelf@nvidia.com>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

+18 -20
+18 -20
rust/kernel/pci.rs
··· 596 596 } 597 597 } 598 598 599 + impl<'a> TryInto<IrqRequest<'a>> for IrqVector<'a> { 600 + type Error = Error; 601 + 602 + fn try_into(self) -> Result<IrqRequest<'a>> { 603 + // SAFETY: `self.as_raw` returns a valid pointer to a `struct pci_dev`. 604 + let irq = unsafe { bindings::pci_irq_vector(self.dev.as_raw(), self.index()) }; 605 + if irq < 0 { 606 + return Err(crate::error::Error::from_errno(irq)); 607 + } 608 + // SAFETY: `irq` is guaranteed to be a valid IRQ number for `&self`. 609 + Ok(unsafe { IrqRequest::new(self.dev.as_ref(), irq as u32) }) 610 + } 611 + } 612 + 599 613 /// Represents an IRQ vector allocation for a PCI device. 600 614 /// 601 615 /// This type ensures that IRQ vectors are properly allocated and freed by ··· 689 675 self.iomap_region_sized::<0>(bar, name) 690 676 } 691 677 692 - /// Returns an [`IrqRequest`] for the given IRQ vector. 693 - pub fn irq_vector(&self, vector: IrqVector<'_>) -> Result<IrqRequest<'_>> { 694 - // Verify that the vector belongs to this device. 695 - if !core::ptr::eq(vector.dev.as_raw(), self.as_raw()) { 696 - return Err(EINVAL); 697 - } 698 - 699 - // SAFETY: `self.as_raw` returns a valid pointer to a `struct pci_dev`. 700 - let irq = unsafe { crate::bindings::pci_irq_vector(self.as_raw(), vector.index()) }; 701 - if irq < 0 { 702 - return Err(crate::error::Error::from_errno(irq)); 703 - } 704 - // SAFETY: `irq` is guaranteed to be a valid IRQ number for `&self`. 705 - Ok(unsafe { IrqRequest::new(self.as_ref(), irq as u32) }) 706 - } 707 - 708 678 /// Returns a [`kernel::irq::Registration`] for the given IRQ vector. 709 679 pub fn request_irq<'a, T: crate::irq::Handler + 'static>( 710 680 &'a self, 711 - vector: IrqVector<'_>, 681 + vector: IrqVector<'a>, 712 682 flags: irq::Flags, 713 683 name: &'static CStr, 714 684 handler: impl PinInit<T, Error> + 'a, 715 685 ) -> Result<impl PinInit<irq::Registration<T>, Error> + 'a> { 716 - let request = self.irq_vector(vector)?; 686 + let request = vector.try_into()?; 717 687 718 688 Ok(irq::Registration::<T>::new(request, flags, name, handler)) 719 689 } ··· 705 707 /// Returns a [`kernel::irq::ThreadedRegistration`] for the given IRQ vector. 706 708 pub fn request_threaded_irq<'a, T: crate::irq::ThreadedHandler + 'static>( 707 709 &'a self, 708 - vector: IrqVector<'_>, 710 + vector: IrqVector<'a>, 709 711 flags: irq::Flags, 710 712 name: &'static CStr, 711 713 handler: impl PinInit<T, Error> + 'a, 712 714 ) -> Result<impl PinInit<irq::ThreadedRegistration<T>, Error> + 'a> { 713 - let request = self.irq_vector(vector)?; 715 + let request = vector.try_into()?; 714 716 715 717 Ok(irq::ThreadedRegistration::<T>::new( 716 718 request, flags, name, handler,