Skip to content

Commit 8b31d2c

Browse files
vlad-kulikovcfriedt
authored andcommitted
smf: simplify get_child_of() loop and rename local to 'state'
Replace the open-ended while(true) with a null-terminated parent walk. Improves readability, behavior is unchanged. Signed-off-by: Vlad Kulikov <[email protected]>
1 parent 2196d2a commit 8b31d2c

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

lib/smf/smf.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,17 @@ static bool is_descendant_of(const struct smf_state *test_state,
3737
static const struct smf_state *get_child_of(const struct smf_state *states,
3838
const struct smf_state *parent)
3939
{
40-
const struct smf_state *tmp = states;
40+
const struct smf_state *state = states;
4141

42-
while (true) {
43-
if (tmp->parent == parent) {
44-
return tmp;
42+
while (state != NULL) {
43+
if (state->parent == parent) {
44+
return state;
4545
}
4646

47-
if (tmp->parent == NULL) {
48-
return NULL;
49-
}
50-
51-
tmp = tmp->parent;
47+
state = state->parent;
5248
}
49+
50+
return NULL;
5351
}
5452

5553
/**

0 commit comments

Comments
 (0)