Skip to content

Commit 20270e5

Browse files
committed
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
1 parent 77410ad commit 20270e5

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

tools/blisp/src/cmd/write.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,31 +168,35 @@ void fill_up_boot_header(struct bfl_boot_header* boot_header) {
168168

169169
blisp_return_t blisp_flash_firmware() {
170170
struct blisp_device device;
171-
blisp_return_t ret;
171+
blisp_return_t ret = BLISP_OK;
172172

173173
if (access(binary_to_write->filename[0], R_OK) != 0) {
174174
// File not accessible, error out.
175175
fprintf(stderr, "Input firmware not found: %s\n", binary_to_write->filename[0]);
176176
cmd_write_args_print_glossary(); /* Print help to assist user */
177177
/* No need to free memory, will now exit with ret code 1 */
178-
return 1;
178+
return BLISP_ERR_CANT_OPEN_FILE;
179179
}
180180

181181
ret = blisp_common_init_device(&device, port_name, chip_type);
182-
183-
if (ret != 0) {
182+
if (ret != BLISP_OK) {
184183
return ret;
185184
}
186185

187-
if (blisp_common_prepare_flash(&device) != 0) {
186+
ret = blisp_common_prepare_flash(&device);
187+
if (ret != BLISP_OK) {
188188
// TODO: Error handling
189189
goto exit1;
190190
}
191191

192192
parsed_firmware_file_t parsed_file;
193193
memset(&parsed_file, 0, sizeof(parsed_file));
194-
int parsed_result =
195-
parse_firmware_file(binary_to_write->filename[0], &parsed_file);
194+
if (parse_firmware_file(binary_to_write->filename[0], &parsed_file) < 0) {
195+
// `parse_firmware_file` doesn't return `blisp_return_t`
196+
// so we default to the generic error.
197+
ret = BLISP_ERR_UNKNOWN;
198+
goto exit1;
199+
}
196200

197201
// If we are injecting a bootloader section, make it, erase flash, and flash
198202
// it. Then when we do firmware later on; it will be located afterwards
@@ -249,7 +253,7 @@ blisp_return_t blisp_flash_firmware() {
249253
&device, &data_transport, parsed_file.payload_address,
250254
parsed_file.payload_length, blisp_common_progress_callback);
251255

252-
if (ret < BLISP_OK) {
256+
if (ret != BLISP_OK) {
253257
fprintf(stderr, "Failed to write app to flash.\n");
254258
goto exit2;
255259
}
@@ -275,6 +279,8 @@ blisp_return_t blisp_flash_firmware() {
275279
free(parsed_file.payload);
276280
exit1:
277281
blisp_device_close(&device);
282+
283+
return ret;
278284
}
279285

280286
blisp_return_t cmd_write_args_init() {

0 commit comments

Comments
 (0)