summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZachary T Welch <zw@superlucidity.net>2009-11-17 13:52:43 -0800
committerZachary T Welch <zw@superlucidity.net>2009-11-19 13:39:41 -0800
commitdd44ae18b49f6cb54a4c361e9fab70f4d0fafeec (patch)
tree0c1366698351edc62b24c01969992c555623168d
parentff25e76bad7e57da4ebd363f1b35d4af04acaa67 (diff)
downloadopenocd_libswd-dd44ae18b49f6cb54a4c361e9fab70f4d0fafeec.tar.gz
openocd_libswd-dd44ae18b49f6cb54a4c361e9fab70f4d0fafeec.tar.bz2
openocd_libswd-dd44ae18b49f6cb54a4c361e9fab70f4d0fafeec.tar.xz
openocd_libswd-dd44ae18b49f6cb54a4c361e9fab70f4d0fafeec.zip
refactor handle_flash_bank_command
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.
-rw-r--r--src/flash/flash.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/flash/flash.c b/src/flash/flash.c
index b960c64e..e93aa636 100644
--- a/src/flash/flash.c
+++ b/src/flash/flash.c
@@ -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)