]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rv/rvgen: enforce presence of initial state
authorWander Lairson Costa <wander@redhat.com>
Mon, 23 Feb 2026 16:18:00 +0000 (13:18 -0300)
committerGabriele Monaco <gmonaco@redhat.com>
Wed, 1 Apr 2026 08:16:20 +0000 (10:16 +0200)
The __get_state_variables() method parses DOT files to identify the
automaton's initial state. If the input file lacks a node with the
required initialization prefix, the initial_state variable is referenced
before assignment, causing an UnboundLocalError or a generic error
during the state removal step.

Initialize the variable explicitly and validate that a start node was
found after parsing. Raise a descriptive AutomataError if the definition
is missing to improve debugging and ensure the automaton is valid.

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

index 9fa17216ca52a0dff0d9233d850f36266d46bfdd..b9f8149f711812793e90b164ae9c46881c6b2693 100644 (file)
@@ -145,6 +145,7 @@ class Automata:
         # wait for node declaration
         states = []
         final_states = []
+        initial_state = ""
 
         has_final_states = False
         cursor = self.__get_cursor_begin_states()
@@ -171,6 +172,9 @@ class Automata:
                     final_states.append(state)
                     has_final_states = True
 
+        if not initial_state:
+            raise AutomataError("The automaton doesn't have an initial state")
+
         states = sorted(set(states))
         states.remove(initial_state)