From 94b752d2b4fba067da7607e2f28016386405efc8 Mon Sep 17 00:00:00 2001 From: Pisit Sawangvonganan Date: Wed, 26 Jun 2024 00:35:10 +0700 Subject: [PATCH] lib: smf: use `while (true)` in `get_child_of` for better clarity Replace the condition-less `for` loop (`;;`) in `get_child_of` with a `while (true)` loop and remove the redundant `return NULL;` at the end, which is never reached. This change aims to enhance readability since `while (true)` is better suited for this scenario. Signed-off-by: Pisit Sawangvonganan --- lib/smf/smf.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/smf/smf.c b/lib/smf/smf.c index 0d7ac258fc1..2c050526a56 100644 --- a/lib/smf/smf.c +++ b/lib/smf/smf.c @@ -36,7 +36,9 @@ static bool share_paren(const struct smf_state *test_state, const struct smf_sta static const struct smf_state *get_child_of(const struct smf_state *states, const struct smf_state *parent) { - for (const struct smf_state *tmp = states;; tmp = tmp->parent) { + const struct smf_state *tmp = states; + + while (true) { if (tmp->parent == parent) { return tmp; } @@ -44,9 +46,9 @@ static const struct smf_state *get_child_of(const struct smf_state *states, if (tmp->parent == NULL) { return NULL; } - } - return NULL; + tmp = tmp->parent; + } } static const struct smf_state *get_last_of(const struct smf_state *states)