From 77d829e31ed7e7c103b88a54df691a7b60901aaa Mon Sep 17 00:00:00 2001 From: Yong Cong Sin Date: Sat, 26 Feb 2022 13:10:21 +0800 Subject: [PATCH] subsys/mgmt/hawkbit: Improve hawkbit_probe readability After the firmware is downloaded in hawkbit_probe, a series of operations are done by using the fact that the conditions of an if-else statement will be ran until a match. This patches separate these condition into individual if-condition for better readability Signed-off-by: Yong Cong Sin --- subsys/mgmt/hawkbit/hawkbit.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/subsys/mgmt/hawkbit/hawkbit.c b/subsys/mgmt/hawkbit/hawkbit.c index 2d86b2d7dc4..950fc389c0c 100644 --- a/subsys/mgmt/hawkbit/hawkbit.c +++ b/subsys/mgmt/hawkbit/hawkbit.c @@ -1264,20 +1264,25 @@ enum hawkbit_response hawkbit_probe(void) if (!hb_context.final_data_received) { LOG_ERR("Download is not complete"); hb_context.code_status = HAWKBIT_DOWNLOAD_ERROR; - } else if (memcmp(response_hash, hb_context.dl.file_hash, - mbedtls_md_get_size(hash_info)) != 0) { + goto free_md; + } + + if (memcmp(response_hash, hb_context.dl.file_hash, mbedtls_md_get_size(hash_info)) != 0) { LOG_ERR("Hash mismatch"); LOG_HEXDUMP_DBG(response_hash, sizeof(response_hash), "resp"); - LOG_HEXDUMP_DBG(hb_context.dl.file_hash, - sizeof(hb_context.dl.file_hash), "file"); + LOG_HEXDUMP_DBG(hb_context.dl.file_hash, sizeof(hb_context.dl.file_hash), "file"); hb_context.code_status = HAWKBIT_DOWNLOAD_ERROR; - } else if (boot_request_upgrade(BOOT_UPGRADE_TEST)) { + goto free_md; + } + + if (boot_request_upgrade(BOOT_UPGRADE_TEST)) { LOG_ERR("Failed to mark the image in slot 1 as pending"); hb_context.code_status = HAWKBIT_DOWNLOAD_ERROR; - } else { + goto free_md; + } + hb_context.code_status = HAWKBIT_UPDATE_INSTALLED; hawkbit_device_acid_update(hb_context.json_action_id); - } hb_context.dl.http_content_size = 0;