-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
Description
Three functions in pci/device.py check whether a sysfs path exists but continue to open() the path even when the check fails. This causes a FileNotFoundError instead of gracefully skipping the operation.
Affected Code
File: pci/device.py
sysfs_remove (lines 449-454):
def sysfs_remove(self):
remove_path = os.path.join(self.dev_path, "remove")
if not os.path.exists(remove_path):
debug("%s remove not present: '%s'", self, remove_path)
# Missing return here — falls through to open()
with open(remove_path, "w") as f:
f.write("1")sysfs_rescan (lines 456-461): Same pattern — missing return after debug log.
sysfs_reset (lines 493-499): Same pattern — missing return after error log.
Expected Behavior
These functions should return early when the path doesn't exist, matching the pattern used by other functions in the same file:
sysfs_power_control_set(line 444): hasreturnsysfs_unbind(line 467): hasreturnsysfs_bind(line 476): hasreturnsysfs_get_driver(line 484): hasreturn Nonesysfs_get_module(line 490): hasreturn None
Suggested Fix
Add return after the existence check in each of the three functions:
def sysfs_remove(self):
remove_path = os.path.join(self.dev_path, "remove")
if not os.path.exists(remove_path):
debug("%s remove not present: '%s'", self, remove_path)
return # <-- add this
with open(remove_path, "w") as f:
f.write("1")Same fix for sysfs_rescan and sysfs_reset.
Version
Tag v2025.11.21 (commit 6495b91)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels