fastload: fix error handling upon running out of memory
authorØyvind Harboe <oyvind.harboe@zylin.com>
Mon, 22 Nov 2010 08:15:47 +0000 (09:15 +0100)
committerØyvind Harboe <oyvind.harboe@zylin.com>
Mon, 22 Nov 2010 08:16:32 +0000 (09:16 +0100)
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
src/target/target.c

index a282aab6ad908919c9307b981022267aa616d176..93efa762f14d5327797a6ba64c0d9eefd93c56e4 100644 (file)
@@ -4964,9 +4964,10 @@ COMMAND_HANDLER(handle_fast_load_image_command)
        struct duration bench;
        duration_start(&bench);
 
-       if (image_open(&image, CMD_ARGV[0], (CMD_ARGC >= 3) ? CMD_ARGV[2] : NULL) != ERROR_OK)
+       retval = image_open(&image, CMD_ARGV[0], (CMD_ARGC >= 3) ? CMD_ARGV[2] : NULL);
+       if (retval != ERROR_OK)
        {
-               return ERROR_OK;
+               return retval;
        }
 
        image_size = 0x0;
@@ -4975,6 +4976,7 @@ COMMAND_HANDLER(handle_fast_load_image_command)
        fastload = (struct FastLoad *)malloc(sizeof(struct FastLoad)*image.num_sections);
        if (fastload == NULL)
        {
+               command_print(CMD_CTX, "out of memory");
                image_close(&image);
                return ERROR_FAIL;
        }
@@ -4986,6 +4988,7 @@ COMMAND_HANDLER(handle_fast_load_image_command)
                {
                        command_print(CMD_CTX, "error allocating buffer for section (%d bytes)",
                                                  (int)(image.sections[i].size));
+                       retval = ERROR_FAIL;
                        break;
                }
 
@@ -5021,6 +5024,9 @@ COMMAND_HANDLER(handle_fast_load_image_command)
                        if (fastload[i].data == NULL)
                        {
                                free(buffer);
+                               command_print(CMD_CTX, "error allocating buffer for section (%d bytes)",
+                                                         length);
+                               retval = ERROR_FAIL;
                                break;
                        }
                        memcpy(fastload[i].data, buffer + offset, length);
@@ -5075,14 +5081,18 @@ COMMAND_HANDLER(handle_fast_load_command)
                command_print(CMD_CTX, "Write to 0x%08x, length 0x%08x",
                                          (unsigned int)(fastload[i].address),
                                          (unsigned int)(fastload[i].length));
-               if (retval == ERROR_OK)
+               retval = target_write_buffer(target, fastload[i].address, fastload[i].length, fastload[i].data);
+               if (retval != ERROR_OK)
                {
-                       retval = target_write_buffer(target, fastload[i].address, fastload[i].length, fastload[i].data);
+                       break;
                }
                size += fastload[i].length;
        }
-       int after = timeval_ms();
-       command_print(CMD_CTX, "Loaded image %f kBytes/s", (float)(size/1024.0)/((float)(after-ms)/1000.0));
+       if (retval == ERROR_OK)
+       {
+               int after = timeval_ms();
+               command_print(CMD_CTX, "Loaded image %f kBytes/s", (float)(size/1024.0)/((float)(after-ms)/1000.0));
+       }
        return retval;
 }
 

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)