Re: [PATCH] PCI: Only restore state that was successfully saved around a reset

From: Lukas Wunner

Date: Tue Nov 10 2026 - 05:34:39 EST


On Tue, Nov 10, 2026 at 01:33:47PM +0800, lirongqing wrote:
> pci_dev_save_and_disable() returns early when config space is inaccessible,
> without saving anything, but pci_dev_restore() calls pci_restore_state()
> unconditionally and pci_restore_state() does not look at state_saved. After
> the reset makes config space accessible again, the all-zero or stale
> saved_config_space[] array is written back to the device, clearing Command,
> BARs and, for bridges, the bus number registers.
>
> Clear state_saved when the save is skipped and only restore when a state
> was saved.

The state_saved flag is used internally by the PCI core for
suspend/resume. If a driver calls pci_save_state() on suspend,
the flag is set and that tells the PCI core that the driver already
put the device into a lower power state, obviating the need for the
PCI core to do that.

Please do not use the flag for a completely different purpose.

Thanks,

Lukas