From: Wander Lairson Costa Date: Mon, 23 Feb 2026 16:17:53 +0000 (-0300) Subject: rv/rvgen: use class constant for init marker X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d474fedcc53aebd584dfc1a42ccb78329ca68aa0;p=thirdparty%2Fkernel%2Flinux.git rv/rvgen: use class constant for init marker Replace hardcoded string literal and magic number with a class constant for the initial state marker in DOT file parsing. The previous implementation used the magic string "__init_" directly in the code along with a hardcoded length of 7 for substring extraction, which made the code less maintainable and harder to understand. This change introduces a class constant init_marker to serve as a single source of truth for the initial state prefix. The code now uses startswith() for clearer intent and calculates the substring position dynamically using len(), eliminating the magic number. If the marker value needs to change in the future, only the constant definition requires updating rather than multiple locations in the code. The refactoring improves code readability and maintainability while preserving the exact same runtime behavior. Signed-off-by: Wander Lairson Costa Reviewed-by: Gabriele Monaco Reviewed-by: Nam Cao Link: https://lore.kernel.org/r/20260223162407.147003-11-wander@redhat.com Signed-off-by: Gabriele Monaco --- diff --git a/tools/verification/rvgen/rvgen/automata.py b/tools/verification/rvgen/rvgen/automata.py index 6b0dc1a8cd6a1..1a02c6f29e41b 100644 --- a/tools/verification/rvgen/rvgen/automata.py +++ b/tools/verification/rvgen/rvgen/automata.py @@ -42,6 +42,7 @@ class Automata: """ invalid_state_str = "INVALID_STATE" + init_marker = "__init_" # val can be numerical, uppercase (constant or macro), lowercase (parameter or function) # only numerical values should have units constraint_rule = re.compile(r""" @@ -136,8 +137,8 @@ class Automata: # "enabled_fired"}; -> enabled_fired state = raw_state.replace('"', '').replace('};', '').replace(',', '_') - if state[0:7] == "__init_": - initial_state = state[7:] + if state.startswith(self.init_marker): + initial_state = state[len(self.init_marker):] else: states.append(state) if "doublecircle" in self.__dot_lines[cursor]: