Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: smf: check for NULL #71213

Merged
merged 1 commit into from
Apr 10, 2024

Conversation

maass-hamburg
Copy link
Collaborator

@maass-hamburg maass-hamburg commented Apr 8, 2024

don't execute share_paren() if the target is NULL
in smf_execute_ancestor_exit_actions()

Fixes: #71215

don't execute share_paren() if the target is NULL
in smf_execute_ancestor_exit_actions()

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
@zephyrbot zephyrbot added the area: State Machine Framework State Machine Framework label Apr 8, 2024
@maass-hamburg maass-hamburg added the bug The issue is a bug, or the PR is fixing a bug label Apr 8, 2024
@nashif nashif merged commit 1ab6f82 into zephyrproject-rtos:main Apr 10, 2024
26 checks passed
@glenn-andrews
Copy link
Collaborator

I'm a bit confused over what situation smf_set_state(ctx, NULL) is a valid function call. Setting state to NULL should be an error, if not a crash.

I feel that exiting in smf_set_state() if new_state == NULL would be a better solution.

@maass-hamburg
Copy link
Collaborator Author

I'm a bit confused over what situation smf_set_state(ctx, NULL) is a valid function call. Setting state to NULL should be an error, if not a crash.

I feel that exiting in smf_set_state() if new_state == NULL would be a better solution.

@glenn-andrews in the docs and header it says explicitly that it is a valid function call:

/**
 * @brief Changes a state machines state. This handles exiting the previous
 *        state and entering the target state. A common parent state will not
 *        exited nor be re-entered.
 *
 * @param ctx       State machine context
 * @param new_state State to transition to (NULL is valid and exits all states)
 */
void smf_set_state(struct smf_ctx *ctx, const struct smf_state *new_state);

@maass-hamburg maass-hamburg deleted the smf_check_for_null branch April 15, 2024 12:31
@glenn-andrews
Copy link
Collaborator

I'm a bit confused over what situation smf_set_state(ctx, NULL) is a valid function call. Setting state to NULL should be an error, if not a crash.
I feel that exiting in smf_set_state() if new_state == NULL would be a better solution.

@glenn-andrews in the docs and header it says explicitly that it is a valid function call:

/**
 * @brief Changes a state machines state. This handles exiting the previous
 *        state and entering the target state. A common parent state will not
 *        exited nor be re-entered.
 *
 * @param ctx       State machine context
 * @param new_state State to transition to (NULL is valid and exits all states)
 */
void smf_set_state(struct smf_ctx *ctx, const struct smf_state *new_state);

My mistake. I apologize.

I'm even more confused about the meaning of 'exits all states'. Does that mean the HSM terminates, or that it calls the exit action, or what?

@maass-hamburg
Copy link
Collaborator Author

maass-hamburg commented Apr 15, 2024

I'm a bit confused over what situation smf_set_state(ctx, NULL) is a valid function call. Setting state to NULL should be an error, if not a crash.
I feel that exiting in smf_set_state() if new_state == NULL would be a better solution.

@glenn-andrews in the docs and header it says explicitly that it is a valid function call:

/**
 * @brief Changes a state machines state. This handles exiting the previous
 *        state and entering the target state. A common parent state will not
 *        exited nor be re-entered.
 *
 * @param ctx       State machine context
 * @param new_state State to transition to (NULL is valid and exits all states)
 */
void smf_set_state(struct smf_ctx *ctx, const struct smf_state *new_state);

My mistake. I apologize.

I'm even more confused about the meaning of 'exits all states'. Does that mean the HSM terminates, or that it calls the exit action, or what?

It calls the exit function the current state and if CONFIG_SMF_ANCESTOR_SUPPORT is enabled also the exit actions of the parents of the current state. But it will not terminate the HSM on its own. I recommend to have smf_set_terminate() be executed in one of the exit action. Preferably at the exit action of the most parent state, because all remaining exit actions are not executed after smf_set_terminate()

@glenn-andrews
Copy link
Collaborator

My mistake. I apologize.
I'm even more confused about the meaning of 'exits all states'. Does that mean the HSM terminates, or that it calls the exit action, or what?

It calls the exit function the current state and if CONFIG_SMF_ANCESTOR_SUPPORT is enabled also the exit actions of the parents of the current state. But it will not terminate the HSM on its own. I recommend to have smf_set_terminate() be executed in one of the exit action. Preferably at the exit action of the most parent state, because all remaining exit actions are not executed after smf_set_terminate()

Oh. I think I see. You're trying to force the existing state machine to act like a terminate event calls all exit actions.

Would the correct way to do that is to have a STATE_TERMINATED outside all other states, and transition to that and call `smf_set_terminated() in the entry action for that state?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: State Machine Framework State Machine Framework bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lib smf: fatal error when state in smf_set_state() is NULL
7 participants