From a2058995a8562737f2e3cbbf57c0392220ec8639 Mon Sep 17 00:00:00 2001 From: Mohamed Omar Asaker Date: Thu, 29 May 2025 14:48:45 +0100 Subject: [PATCH 1/2] mod/system_coordinator: Fix handling of final phase transition Ensure phase processing only occurs when the next phase index is valid. Previously, a timer could be started or a phase event sent even if the current phase was the last one, depending on the `phase_us` value. This patch adds a check to prevent processing beyond the last valid phase, ensuring safe termination of the phase sequence. Signed-off-by: Mohamed Omar Asaker --- .../src/mod_system_coordinator.c | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/module/system_coordinator/src/mod_system_coordinator.c b/module/system_coordinator/src/mod_system_coordinator.c index 405b2ac53..a5dffe6ee 100644 --- a/module/system_coordinator/src/mod_system_coordinator.c +++ b/module/system_coordinator/src/mod_system_coordinator.c @@ -1,6 +1,6 @@ /* * Arm SCP/MCP Software - * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved. + * Copyright (c) 2024-2025, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -148,20 +148,22 @@ static int process_current_phase(const struct phase_event_params *params) phase_ctx = &system_coordinator_ctx.phase_ctx[params->phase_idx]; next_phase_params.phase_idx = params->phase_idx + 1; next_phase_params.cycle_count = params->cycle_count; + if (next_phase_params.phase_idx < system_coordinator_ctx.phase_count) { + if (phase_ctx->phase_config->phase_us == 0) { + /* Send event to process next phase if current phase timer is 0 */ + status = send_phase_event(&next_phase_params); + } else if ( + params->phase_idx <= (system_coordinator_ctx.phase_count - 1)) { + /* + * Start timer for next phase. Timer will be skip if the phase is + * the last phase or the phase time value is 0. + */ + status = start_timer_for_next_phase(phase_ctx, &next_phase_params); + } - if (phase_ctx->phase_config->phase_us == 0) { - /* Send event to process next phase if current phase timer is 0 */ - status = send_phase_event(&next_phase_params); - } else if (params->phase_idx < (system_coordinator_ctx.phase_count - 1)) { - /* - * Start timer for next phase. Timer will be skip if the phase is the - * last phase or the phase time value is 0. - */ - status = start_timer_for_next_phase(phase_ctx, &next_phase_params); - } - - if (status != FWK_SUCCESS) { - return status; + if (status != FWK_SUCCESS) { + return status; + } } /* Call phase API */ -- GitLab From 7f6a81ecf6d0ea98f8ba673cb251bf615dd1e280 Mon Sep 17 00:00:00 2001 From: Mohamed Omar Asaker Date: Thu, 22 May 2025 17:12:35 +0100 Subject: [PATCH 2/2] mod/system-coordinator: Fix log format specifiers in phase event error Replace PRIu32-based format specifiers with standard `%u` for logging `unsigned int` values. This simplifies format strings and ensures correct output for `status`, `phase_idx`, and `__LINE__`. Signed-off-by: Mohamed Omar Asaker --- module/system_coordinator/src/mod_system_coordinator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/system_coordinator/src/mod_system_coordinator.c b/module/system_coordinator/src/mod_system_coordinator.c index a5dffe6ee..fba13a3e0 100644 --- a/module/system_coordinator/src/mod_system_coordinator.c +++ b/module/system_coordinator/src/mod_system_coordinator.c @@ -86,7 +86,7 @@ static int send_phase_event(struct phase_event_params *params) status = fwk_put_event(&phase_event); if (status != FWK_SUCCESS) { FWK_LOG_ERR( - MOD_NAME "%s@%" PRIu32 " status=%" PRIu32 ", phase_idx=%" PRIu32 "", + MOD_NAME "%s@%u status=%u, phase_idx=%u", __func__, __LINE__, status, -- GitLab