···228228 if (!ret) {229229 /* D3 might be unsupported via quirk, skip unless in D3 */230230 if (needs_save && pdev->current_state >= PCI_D3hot) {231231+ /*232232+ * The current PCI state will be saved locally in233233+ * 'pm_save' during the D3hot transition. When the234234+ * device state is changed to D0 again with the current235235+ * function, then pci_store_saved_state() will restore236236+ * the state and will free the memory pointed by237237+ * 'pm_save'. There are few cases where the PCI power238238+ * state can be changed to D0 without the involvement239239+ * of the driver. For these cases, free the earlier240240+ * allocated memory first before overwriting 'pm_save'241241+ * to prevent the memory leak.242242+ */243243+ kfree(vdev->pm_save);231244 vdev->pm_save = pci_store_saved_state(pdev);232245 } else if (needs_restore) {233246 pci_load_and_free_saved_state(pdev, &vdev->pm_save);···334321335322 /* For needs_reset */336323 lockdep_assert_held(&vdev->vdev.dev_set->lock);324324+325325+ /*326326+ * This function can be invoked while the power state is non-D0.327327+ * This function calls __pci_reset_function_locked() which internally328328+ * can use pci_pm_reset() for the function reset. pci_pm_reset() will329329+ * fail if the power state is non-D0. Also, for the devices which330330+ * have NoSoftRst-, the reset function can cause the PCI config space331331+ * reset without restoring the original state (saved locally in332332+ * 'vdev->pm_save').333333+ */334334+ vfio_pci_set_power_state(vdev, PCI_D0);337335338336 /* Stop the device from further DMA */339337 pci_clear_master(pdev);···945921 return -EINVAL;946922947923 vfio_pci_zap_and_down_write_memory_lock(vdev);924924+925925+ /*926926+ * This function can be invoked while the power state is non-D0.927927+ * If pci_try_reset_function() has been called while the power928928+ * state is non-D0, then pci_try_reset_function() will929929+ * internally set the power state to D0 without vfio driver930930+ * involvement. For the devices which have NoSoftRst-, the931931+ * reset function can cause the PCI config space reset without932932+ * restoring the original state (saved locally in933933+ * 'vdev->pm_save').934934+ */935935+ vfio_pci_set_power_state(vdev, PCI_D0);936936+948937 ret = pci_try_reset_function(vdev->pdev);949938 up_write(&vdev->memory_lock);950939···20732036 }20742037 cur_mem = NULL;2075203820392039+ /*20402040+ * The pci_reset_bus() will reset all the devices in the bus.20412041+ * The power state can be non-D0 for some of the devices in the bus.20422042+ * For these devices, the pci_reset_bus() will internally set20432043+ * the power state to D0 without vfio driver involvement.20442044+ * For the devices which have NoSoftRst-, the reset function can20452045+ * cause the PCI config space reset without restoring the original20462046+ * state (saved locally in 'vdev->pm_save').20472047+ */20482048+ list_for_each_entry(cur, &dev_set->device_list, vdev.dev_set_list)20492049+ vfio_pci_set_power_state(cur, PCI_D0);20502050+20762051 ret = pci_reset_bus(pdev);2077205220782053err_undo:···21372088 pdev = vfio_pci_dev_set_resettable(dev_set);21382089 if (!pdev)21392090 return false;20912091+20922092+ /*20932093+ * The pci_reset_bus() will reset all the devices in the bus.20942094+ * The power state can be non-D0 for some of the devices in the bus.20952095+ * For these devices, the pci_reset_bus() will internally set20962096+ * the power state to D0 without vfio driver involvement.20972097+ * For the devices which have NoSoftRst-, the reset function can20982098+ * cause the PCI config space reset without restoring the original20992099+ * state (saved locally in 'vdev->pm_save').21002100+ */21012101+ list_for_each_entry(cur, &dev_set->device_list, vdev.dev_set_list)21022102+ vfio_pci_set_power_state(cur, PCI_D0);2140210321412104 ret = pci_reset_bus(pdev);21422105 if (ret)