Skip to content

Commit 77d829e

Browse files
ycsincarlescufi
authored andcommitted
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 <[email protected]>
1 parent c128a89 commit 77d829e

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

subsys/mgmt/hawkbit/hawkbit.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,20 +1264,25 @@ enum hawkbit_response hawkbit_probe(void)
12641264
if (!hb_context.final_data_received) {
12651265
LOG_ERR("Download is not complete");
12661266
hb_context.code_status = HAWKBIT_DOWNLOAD_ERROR;
1267-
} else if (memcmp(response_hash, hb_context.dl.file_hash,
1268-
mbedtls_md_get_size(hash_info)) != 0) {
1267+
goto free_md;
1268+
}
1269+
1270+
if (memcmp(response_hash, hb_context.dl.file_hash, mbedtls_md_get_size(hash_info)) != 0) {
12691271
LOG_ERR("Hash mismatch");
12701272
LOG_HEXDUMP_DBG(response_hash, sizeof(response_hash), "resp");
1271-
LOG_HEXDUMP_DBG(hb_context.dl.file_hash,
1272-
sizeof(hb_context.dl.file_hash), "file");
1273+
LOG_HEXDUMP_DBG(hb_context.dl.file_hash, sizeof(hb_context.dl.file_hash), "file");
12731274
hb_context.code_status = HAWKBIT_DOWNLOAD_ERROR;
1274-
} else if (boot_request_upgrade(BOOT_UPGRADE_TEST)) {
1275+
goto free_md;
1276+
}
1277+
1278+
if (boot_request_upgrade(BOOT_UPGRADE_TEST)) {
12751279
LOG_ERR("Failed to mark the image in slot 1 as pending");
12761280
hb_context.code_status = HAWKBIT_DOWNLOAD_ERROR;
1277-
} else {
1281+
goto free_md;
1282+
}
1283+
12781284
hb_context.code_status = HAWKBIT_UPDATE_INSTALLED;
12791285
hawkbit_device_acid_update(hb_context.json_action_id);
1280-
}
12811286

12821287
hb_context.dl.http_content_size = 0;
12831288

0 commit comments

Comments
 (0)