[PATCH 3/4] PCI/PM: Do not restore a config space snapshot that is all ones
From: Francisco Beltrán Millalén
Date: Thu Sep 24 2026 - 08:45:36 EST
Belt and braces for the previous patch: even if a snapshot of all ones
is somehow recorded, never write it back. The vendor ID of a device
that was present can never be 0xffffffff, so a snapshot whose first
dword is all ones is known to be garbage.
Signed-off-by: Francisco Beltrán Millalén <fbeltranmillalen@xxxxxxxxx>
---
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1833,6 +1833,17 @@
static void pci_restore_config_space(struct pci_dev *pdev)
{
+ /*
+ * Vendor and Device ID are read-only, so a snapshot whose first
+ * dword reads as all ones was taken from an inaccessible device and
+ * is garbage. Writing it back would corrupt a device that has since
+ * become accessible again, so leave the hardware alone.
+ */
+ if (PCI_POSSIBLE_ERROR(pdev->saved_config_space[0])) {
+ pci_warn(pdev, "not restoring config space, saved state is invalid\n");
+ return;
+ }
+
if (pdev->hdr_type == PCI_HEADER_TYPE_NORMAL) {
pci_restore_config_space_range(pdev, 10, 15, 0, false);
/* Restore BARs before the command register. */