refactor handle_flash_bank_command
authorZachary T Welch <zw@superlucidity.net>
Tue, 17 Nov 2009 21:52:43 +0000 (13:52 -0800)
committerZachary T Welch <zw@superlucidity.net>
Thu, 19 Nov 2009 21:39:41 +0000 (13:39 -0800)
Move variables to point of first use, reducing their scope.
Add driver_name temporary to help arguments be changed later.

Eliminates the useless 'found' variable, changing the code to terminate
the loop immediate and return its success.

src/flash/flash.c

index b960c64edd9d9c3295798f65c3084b4a8abc307f..e93aa6366ef30adea7eeedcac213127c5f006d77 100644 (file)
@@ -239,25 +239,24 @@ COMMAND_HELPER(flash_command_get_bank, unsigned name_index,
 
 COMMAND_HANDLER(handle_flash_bank_command)
 {
-       int retval;
-       int i;
-       int found = 0;
-       struct target *target;
-
        if (CMD_ARGC < 6)
        {
+               LOG_ERROR("usage: flash bank <driver> "
+                               "<base> <size> <chip_width> <bus_width>");
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
+       struct target *target;
        if ((target = get_target(CMD_ARGV[5])) == NULL)
        {
                LOG_ERROR("target '%s' not defined", CMD_ARGV[5]);
                return ERROR_FAIL;
        }
 
-       for (i = 0; flash_drivers[i]; i++)
+       const char *driver_name = CMD_ARGV[0];
+       for (unsigned i = 0; flash_drivers[i]; i++)
        {
-               if (strcmp(CMD_ARGV[0], flash_drivers[i]->name) != 0)
+               if (strcmp(driver_name, flash_drivers[i]->name) != 0)
                        continue;
 
                struct flash_bank *p, *c;
@@ -265,7 +264,7 @@ COMMAND_HANDLER(handle_flash_bank_command)
                /* register flash specific commands */
                if (flash_drivers[i]->register_commands(CMD_CTX) != ERROR_OK)
                {
-                       LOG_ERROR("couldn't register '%s' commands", CMD_ARGV[0]);
+                       LOG_ERROR("couldn't register '%s' commands", driver_name);
                        return ERROR_FAIL;
                }
 
@@ -281,10 +280,12 @@ COMMAND_HANDLER(handle_flash_bank_command)
                c->sectors = NULL;
                c->next = NULL;
 
+               int retval;
                retval = CALL_COMMAND_HANDLER(flash_drivers[i]->flash_bank_command, c);
                if (ERROR_OK != retval)
                {
-                       LOG_ERROR("'%s' driver rejected flash bank at 0x%8.8" PRIx32 , CMD_ARGV[0], c->base);
+                       LOG_ERROR("'%s' driver rejected flash bank at 0x%8.8" PRIx32,
+                                       driver_name, c->base);
                        free(c);
                        return retval;
                }
@@ -305,17 +306,12 @@ COMMAND_HANDLER(handle_flash_bank_command)
                        c->bank_number = 0;
                }
 
-               found = 1;
+               return ERROR_OK;
        }
 
        /* no matching flash driver found */
-       if (!found)
-       {
-               LOG_ERROR("flash driver '%s' not found", CMD_ARGV[0]);
-               return ERROR_FAIL;
-       }
-
-       return ERROR_OK;
+       LOG_ERROR("flash driver '%s' not found", driver_name);
+       return ERROR_FAIL;
 }
 
 COMMAND_HANDLER(handle_flash_info_command)

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)