NVIDIA / NVIDIA/gpu-admin-tools

Bug: sysfs_remove, sysfs_rescan, and sysfs_reset proceed to open() after detecting missing path

Open Beginner friendly
#16 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
92
Forks
35
PR merge metrics
No merged PRs in 30d

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): 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)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in pci/device.py at sysfs_remove, sysfs_rescan, and sysfs_reset, and compare their missing-path checks with sysfs_power_control_set, sysfs_unbind, and sysfs_bind. Done means each function returns immediately after logging when its sysfs path does not exist, avoiding the subsequent open() and FileNotFoundError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
operating-systems
Issue type
Bug
Difficulty
1/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.