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): has return
sysfs_unbind (line 467): has return
sysfs_bind (line 476): has return
sysfs_get_driver (line 484): has return None
sysfs_get_module (line 490): has return 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)
Description
Three functions in
pci/device.pycheck whether a sysfs path exists but continue toopen()the path even when the check fails. This causes aFileNotFoundErrorinstead of gracefully skipping the operation.Affected Code
File:
pci/device.pysysfs_remove(lines 449-454):sysfs_rescan(lines 456-461): Same pattern — missingreturnafter debug log.sysfs_reset(lines 493-499): Same pattern — missingreturnafter 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 NoneSuggested Fix
Add
returnafter the existence check in each of the three functions:Same fix for
sysfs_rescanandsysfs_reset.Version
Tag
v2025.11.21(commit6495b91)