Laurentiu Cocanu - more error handling fixes
[openocd.git] / src / flash / flash.c
index b2ebe0b79a0491f787feca8c4b38e59f6e951db8..d5f89de6cf6acd4d6619dee284a5fbf1850a3961 100644 (file)
@@ -80,25 +80,23 @@ extern flash_driver_t lpc288x_flash;
 extern flash_driver_t ocl_flash;
 
 flash_driver_t *flash_drivers[] = {
-        &lpc2000_flash,
-        &cfi_flash,
-        &at91sam7_flash,
-        &at91sam7_old_flash,
-        &str7x_flash,
-        &str9x_flash,
-        &aduc702x_flash,
-        &stellaris_flash,
-        &str9xpec_flash,
-        &stm32x_flash,
-        &tms470_flash,
-        &ecosflash_flash,
-        &lpc288x_flash,
-        &ocl_flash,
-        NULL,
+       &lpc2000_flash,
+       &cfi_flash,
+       &at91sam7_flash,
+       &at91sam7_old_flash,
+       &str7x_flash,
+       &str9x_flash,
+       &aduc702x_flash,
+       &stellaris_flash,
+       &str9xpec_flash,
+       &stm32x_flash,
+       &tms470_flash,
+       &ecosflash_flash,
+       &lpc288x_flash,
+       &ocl_flash,
+       NULL,
 };
 
-
-
 flash_bank_t *flash_banks;
 static         command_t *flash_cmd;
 
@@ -516,7 +514,11 @@ int handle_flash_erase_address_command(struct command_context_s *cmd_ctx, char *
 
        if ((retval = flash_erase_address_range(target, address, length)) == ERROR_OK)
        {
-               duration_stop_measure(&duration, &duration_text);
+               if ((retval = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
+               {
+                       free(duration_text);
+                       return retval;
+               }
                command_print(cmd_ctx, "erased address 0x%8.8x length %i in %s", address, length, duration_text);
                free(duration_text);
        }
@@ -578,7 +580,11 @@ int handle_flash_erase_command(struct command_context_s *cmd_ctx, char *cmd, cha
 
                if ((retval = flash_driver_erase(p, first, last)) == ERROR_OK)
                {
-                       duration_stop_measure(&duration, &duration_text);
+                       if ((retval = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
+                       {
+                               free(duration_text);
+                               return retval;
+                       }
 
                        command_print(cmd_ctx, "erased sectors %i through %i on flash bank %i in %s", first, last, strtoul(args[0], 0, 0), duration_text);
                        free(duration_text);
@@ -641,7 +647,7 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm
        duration_t duration;
        char *duration_text;
 
-       int retval;
+       int retval, retvaltemp;
 
        if (argc < 1)
        {
@@ -699,7 +705,12 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm
                return retval;
        }
 
-       duration_stop_measure(&duration, &duration_text);
+       if ((retvaltemp = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
+       {
+               free(duration_text);
+               image_close(&image);
+               return retvaltemp;
+       }
        if (retval == ERROR_OK)
        {
                command_print(cmd_ctx, "wrote %u byte from file %s in %s (%f kb/s)",
@@ -715,7 +726,7 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm
 
 int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
 {
-       int err = ERROR_OK;
+       int err = ERROR_OK, retval;
        u32 address;
        u32 pattern;
        u32 count;
@@ -805,7 +816,12 @@ int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char
                }
        }
 
-       duration_stop_measure(&duration, &duration_text);
+       if ((retval = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
+       {
+               free(duration_text);
+               return retval;
+       }
+
 
        if(err == ERROR_OK)
        {
@@ -831,7 +847,7 @@ int handle_flash_write_bank_command(struct command_context_s *cmd_ctx, char *cmd
        duration_t duration;
        char *duration_text;
 
-       int retval;
+       int retval, retvaltemp;
        flash_bank_t *p;
 
        if (argc != 3)
@@ -867,7 +883,12 @@ int handle_flash_write_bank_command(struct command_context_s *cmd_ctx, char *cmd
        free(buffer);
        buffer = NULL;
 
-       duration_stop_measure(&duration, &duration_text);
+       if ((retvaltemp = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
+       {
+               free(duration_text);
+               fileio_close(&fileio);
+               return retvaltemp;
+       }
        if (retval!=ERROR_OK)
        {
        command_print(cmd_ctx, "wrote  %"PRIi64" byte from file %s to flash bank %i at offset 0x%8.8x in %s (%f kb/s)",

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)