Skip to content

Commit 2d151b2

Browse files
vlad-kulikovcfriedt
authored andcommitted
lib: smf: remove unreachable case in get_lca_of()
smf_set_state() excludes ancestor/descendant relations before calling get_lca_of(). The function now walks from source->parent and returns the first ancestor that contains dest. The 'ancestor == dest' case was unreachable and is removed. No functional change intended. Ref: RFC #95952 Signed-off-by: Vlad Kulikov <[email protected]>
1 parent ca641d8 commit 2d151b2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/smf/smf.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ static const struct smf_state *get_last_of(const struct smf_state *states)
5757
}
5858

5959
/**
60-
* @brief Find the Least Common Ancestor (LCA) of two states
60+
* @brief Find the Least Common Ancestor (LCA) of two states,
61+
* that are not ancestors of one another.
6162
*
6263
* @param source transition source
6364
* @param dest transition destination
@@ -68,9 +69,8 @@ static const struct smf_state *get_lca_of(const struct smf_state *source,
6869
{
6970
for (const struct smf_state *ancestor = source->parent; ancestor != NULL;
7071
ancestor = ancestor->parent) {
71-
if (ancestor == dest) {
72-
return ancestor->parent;
73-
} else if (share_parent(dest, ancestor)) {
72+
/* First common ancestor */
73+
if (share_parent(dest, ancestor)) {
7474
return ancestor;
7575
}
7676
}

0 commit comments

Comments
 (0)