Skip to content

Commit 5b0b1a3

Browse files
committed
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 730efd9 commit 5b0b1a3

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
@@ -36,19 +36,17 @@ static bool share_parent(const struct smf_state *test_state, const struct smf_st
3636
static const struct smf_state *get_child_of(const struct smf_state *states,
3737
const struct smf_state *parent)
3838
{
39-
const struct smf_state *tmp = states;
39+
const struct smf_state *state = states;
4040

41-
while (true) {
42-
if (tmp->parent == parent) {
43-
return tmp;
41+
while (state) {
42+
if (state->parent == parent) {
43+
return state;
4444
}
4545

46-
if (tmp->parent == NULL) {
47-
return NULL;
48-
}
49-
50-
tmp = tmp->parent;
46+
state = state->parent;
5147
}
48+
49+
return NULL;
5250
}
5351

5452
static const struct smf_state *get_last_of(const struct smf_state *states)

0 commit comments

Comments
 (0)