From 9d37d15827e7ef1fe3ffdc847cdcd8ca2351be89 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 9 Jun 2024 18:14:18 +0200 Subject: [PATCH] pcid: Avoid duplicate read of vendor and device id --- pcid/src/pci_header.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pcid/src/pci_header.rs b/pcid/src/pci_header.rs index 471f74b27c..95c960851a 100644 --- a/pcid/src/pci_header.rs +++ b/pcid/src/pci_header.rs @@ -42,12 +42,13 @@ impl PciHeader { access: &impl ConfigRegionAccess, addr: PciAddress, ) -> Result { - if unsafe { access.read(addr, 0) } == 0xffffffff { + let header = TyPciHeader::new(addr); + let (vendor_id, device_id) = header.id(access); + + if vendor_id == 0xffff && device_id == 0xffff { return Err(PciHeaderError::NoDevice); } - let header = TyPciHeader::new(addr); - let (vendor_id, device_id) = header.id(access); let (revision, class, subclass, interface) = header.revision_and_class(access); let header_type = header.header_type(access); let shared = SharedPciHeader {