From eb1bf1f27376d8061b1c52dc01336135298bef5d Mon Sep 17 00:00:00 2001 From: Filip Strajnar Date: Sun, 27 Oct 2024 09:56:52 +0100 Subject: [PATCH] Check if driver bind path exists before binding. --- src/pci_passthrough_assist/pci_device.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pci_passthrough_assist/pci_device.py b/src/pci_passthrough_assist/pci_device.py index bb7f723..a44135e 100644 --- a/src/pci_passthrough_assist/pci_device.py +++ b/src/pci_passthrough_assist/pci_device.py @@ -42,8 +42,12 @@ class PciDevice: if unbind_first: self.unbind_driver() - with open(f"/sys/bus/pci/drivers/{driver_to_bind}/bind", - "w") as driver: + driver_bind_path = f"/sys/bus/pci/drivers/{driver_to_bind}/bind" + if not exists(driver_bind_path): + print(f"Can't bind to driver: {driver_bind_path}.") + return + + with open(driver_bind_path, "w") as driver: driver.write(self.device_id) def devices_in_iommu_group(self) -> list['PciDevice']: