summaryrefslogtreecommitdiff
path: root/backport-ensure-that-pci_read_config-initialises-all-fields.patch
diff options
context:
space:
mode:
Diffstat (limited to 'backport-ensure-that-pci_read_config-initialises-all-fields.patch')
-rw-r--r--backport-ensure-that-pci_read_config-initialises-all-fields.patch45
1 files changed, 45 insertions, 0 deletions
diff --git a/backport-ensure-that-pci_read_config-initialises-all-fields.patch b/backport-ensure-that-pci_read_config-initialises-all-fields.patch
new file mode 100644
index 0000000..a03b950
--- /dev/null
+++ b/backport-ensure-that-pci_read_config-initialises-all-fields.patch
@@ -0,0 +1,45 @@
+From 04288974f6d81019314cbf9cbd72ab1fae95496f Mon Sep 17 00:00:00 2001
+From: Michael Brown <mcb30@ipxe.org>
+Date: Wed, 16 Feb 2022 12:30:02 +0000
+Subject: [PATCH] [pci] Ensure that pci_read_config() initialises all fields
+
+As per the general pattern for initialisation functions in iPXE,
+pci_init() saves code size by assuming that the caller has already
+zeroed the underlying storage (e.g. as part of zeroing a larger
+containing structure). There are several places within the code where
+pci_init() is deliberately used to initialise a transient struct
+pci_device without zeroing the entire structure, because the calling
+code knows that only the PCI bus:dev.fn address is required to be
+initialised (e.g. when reading from PCI configuration space).
+
+Ensure that using pci_init() followed by pci_read_config() will fully
+initialise the struct pci_device even if the caller did not previously
+zero the underlying storage, since Coverity reports that there are
+several places in the code that rely upon this.
+
+Signed-off-by: Michael Brown <mcb30@ipxe.org>
+
+Conflict:NA
+Reference:https://github.com/ipxe/ipxe/commit/04288974f6d81019314cbf9cbd72ab1fae95496f
+---
+ src/drivers/bus/pci.c | 5 +++++
+ 1 file changed, 5 insertions(+)
+
+diff --git a/src/drivers/bus/pci.c b/src/drivers/bus/pci.c
+index 1b7350c8b8..5891e42ff4 100644
+--- a/src/drivers/bus/pci.c
++++ b/src/drivers/bus/pci.c
+@@ -121,6 +121,11 @@ static void pci_read_bases ( struct pci_device *pci ) {
+ unsigned long bar;
+ int reg;
+
++ /* Clear any existing base addresses */
++ pci->ioaddr = 0;
++ pci->membase = 0;
++
++ /* Get first memory and I/O BAR addresses */
+ for ( reg = PCI_BASE_ADDRESS_0; reg <= PCI_BASE_ADDRESS_5; reg += 4 ) {
+ bar = pci_bar ( pci, reg );
+ if ( bar & PCI_BASE_ADDRESS_SPACE_IO ) {
+
+