Skip to content

refactor: simplify bind_one logic and consolidate pci write handlers - #188

Open
bhagathkrishnacdac wants to merge 1 commit into
omec-project:mainfrom
bhagathkrishnacdac:bess-devbind-complexity
Open

refactor: simplify bind_one logic and consolidate pci write handlers#188
bhagathkrishnacdac wants to merge 1 commit into
omec-project:mainfrom
bhagathkrishnacdac:bess-devbind-complexity

Conversation

@bhagathkrishnacdac

Copy link
Copy Markdown

Description
This PR refactors the PCI device binding function (bind_one) in the DPDK binding utility to simplify exception handling and guarantee file resource safety.

Key Changes

  • Context Managers (with): Replaced manual, unsafe open() and close() operations with Python context managers to guarantee file closure during I/O failures.
  • Consolidated File Handlers:
    • Extracted _prepare_pci_driver to manage driver_override and new_id updates for kernel compatibility.
    • Extracted _finalize_bind to handle standard binds and automate driver rollback operations on failure.
  • Unified Exception Catching: Grouped separate file-open and file-write try/except segments into unified blocks catching (OSError, IOError) exceptions, reducing function length and complexity.

Signed-off-by: bhagathkrishnacdac <bhagath.krishna@cdac.in>
@bhagathkrishnacdac
bhagathkrishnacdac requested a review from a team August 2, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant