Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <wander@redhat.com>
Reviewed-by: Gabriele Monaco <gmonaco@redhat.com>
Reviewed-by: Nam Cao <namcao@linutronix.de>
Link: https://lore.kernel.org/r/20260223162407.147003-11-wander@redhat.com
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>

authored by

Wander Lairson Costa and committed by
Gabriele Monaco
d474fedc 5d5a7d88

+3 -2
+3 -2
tools/verification/rvgen/rvgen/automata.py
··· 42 42 """ 43 43 44 44 invalid_state_str = "INVALID_STATE" 45 + init_marker = "__init_" 45 46 # val can be numerical, uppercase (constant or macro), lowercase (parameter or function) 46 47 # only numerical values should have units 47 48 constraint_rule = re.compile(r""" ··· 137 136 138 137 # "enabled_fired"}; -> enabled_fired 139 138 state = raw_state.replace('"', '').replace('};', '').replace(',', '_') 140 - if state[0:7] == "__init_": 141 - initial_state = state[7:] 139 + if state.startswith(self.init_marker): 140 + initial_state = state[len(self.init_marker):] 142 141 else: 143 142 states.append(state) 144 143 if "doublecircle" in self.__dot_lines[cursor]: