]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
rv/rvgen: use context managers for file operations
authorWander Lairson Costa <wander@redhat.com>
Mon, 23 Feb 2026 16:17:49 +0000 (13:17 -0300)
committerGabriele Monaco <gmonaco@redhat.com>
Tue, 31 Mar 2026 14:47:51 +0000 (16:47 +0200)
commit6c7e548e313dcfbb8a4965b9b93c5c59537b35d9
treef8e7ef39220d337e0b3aa8a8ef778402bd92496a
parentc4258d8160b2a40732f3fe5272a9ec524e0a5e94
rv/rvgen: use context managers for file operations

Replace manual file open and close operations with context managers
throughout the rvgen codebase. The previous implementation used
explicit open() and close() calls, which could lead to resource leaks
if exceptions occurred between opening and closing the file handles.

This change affects three file operations: reading DOT specification
files in the automata parser, reading template files in the generator
base class, and writing generated monitor files. All now use the with
statement to ensure proper resource cleanup even in error conditions.

Context managers provide automatic cleanup through the with statement,
which guarantees that file handles are closed when the with block
exits regardless of whether an exception occurred. This follows PEP
343 recommendations and is the standard Python idiom for resource
management. The change also reduces code verbosity while improving
safety and maintainability.

Signed-off-by: Wander Lairson Costa <wander@redhat.com>
Reviewed-by: Nam Cao <namcao@linutronix.de>
Reviewed-by: Gabriele Monaco <gmonaco@redhat.com>
Link: https://lore.kernel.org/r/20260223162407.147003-7-wander@redhat.com
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
tools/verification/rvgen/rvgen/automata.py
tools/verification/rvgen/rvgen/generator.py