From 20270e520144ae3c503706fe02b81862b366dd96 Mon Sep 17 00:00:00 2001 From: "Berk D. Demir" Date: Wed, 9 Jul 2025 21:39:14 -0700 Subject: [PATCH] Fix compiler warnings: blisp_flash_firmware Improve blisp_flash_firmware error handling: - Address never checked return of `parse_firmware_file` - Ensure the function always returns the correct blisp_return_t value - Make error checking syntactic dance consistent --- tools/blisp/src/cmd/write.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tools/blisp/src/cmd/write.c b/tools/blisp/src/cmd/write.c index a53390b..d28f48a 100644 --- a/tools/blisp/src/cmd/write.c +++ b/tools/blisp/src/cmd/write.c @@ -168,31 +168,35 @@ void fill_up_boot_header(struct bfl_boot_header* boot_header) { blisp_return_t blisp_flash_firmware() { struct blisp_device device; - blisp_return_t ret; + blisp_return_t ret = BLISP_OK; if (access(binary_to_write->filename[0], R_OK) != 0) { // File not accessible, error out. fprintf(stderr, "Input firmware not found: %s\n", binary_to_write->filename[0]); cmd_write_args_print_glossary(); /* Print help to assist user */ /* No need to free memory, will now exit with ret code 1 */ - return 1; + return BLISP_ERR_CANT_OPEN_FILE; } ret = blisp_common_init_device(&device, port_name, chip_type); - - if (ret != 0) { + if (ret != BLISP_OK) { return ret; } - if (blisp_common_prepare_flash(&device) != 0) { + ret = blisp_common_prepare_flash(&device); + if (ret != BLISP_OK) { // TODO: Error handling goto exit1; } parsed_firmware_file_t parsed_file; memset(&parsed_file, 0, sizeof(parsed_file)); - int parsed_result = - parse_firmware_file(binary_to_write->filename[0], &parsed_file); + if (parse_firmware_file(binary_to_write->filename[0], &parsed_file) < 0) { + // `parse_firmware_file` doesn't return `blisp_return_t` + // so we default to the generic error. + ret = BLISP_ERR_UNKNOWN; + goto exit1; + } // If we are injecting a bootloader section, make it, erase flash, and flash // it. Then when we do firmware later on; it will be located afterwards @@ -249,7 +253,7 @@ blisp_return_t blisp_flash_firmware() { &device, &data_transport, parsed_file.payload_address, parsed_file.payload_length, blisp_common_progress_callback); - if (ret < BLISP_OK) { + if (ret != BLISP_OK) { fprintf(stderr, "Failed to write app to flash.\n"); goto exit2; } @@ -275,6 +279,8 @@ exit2: free(parsed_file.payload); exit1: blisp_device_close(&device); + + return ret; } blisp_return_t cmd_write_args_init() {