Improve flash indentation.

Removes redundant tests and reverses backwards logic to reduce the
indentation level in flash.c.
This commit is contained in:
Zachary T Welch 2009-11-05 23:52:03 -08:00
parent c5f56437c0
commit ff61e6a37c
1 changed files with 215 additions and 226 deletions

View File

@ -177,8 +177,9 @@ int flash_init_drivers(struct command_context_s *cmd_ctx)
{
register_jim(cmd_ctx, "ocd_flash_banks", jim_flash_banks, "return information about the flash banks");
if (flash_banks)
{
if (!flash_banks)
return ERROR_OK;
register_command(cmd_ctx, flash_cmd, "info", handle_flash_info_command, COMMAND_EXEC,
"print info about flash bank <num>");
register_command(cmd_ctx, flash_cmd, "probe", handle_flash_probe_command, COMMAND_EXEC,
@ -205,7 +206,6 @@ int flash_init_drivers(struct command_context_s *cmd_ctx)
"write_image [erase] [unlock] <file> [offset] [type]");
register_command(cmd_ctx, flash_cmd, "protect", handle_flash_protect_command, COMMAND_EXEC,
"set protection of sectors at <bank> <first> <last> <on | off>");
}
return ERROR_OK;
}
@ -292,8 +292,9 @@ static int handle_flash_bank_command(struct command_context_s *cmd_ctx, char *cm
for (i = 0; flash_drivers[i]; i++)
{
if (strcmp(args[0], flash_drivers[i]->name) == 0)
{
if (strcmp(args[0], flash_drivers[i]->name) != 0)
continue;
flash_bank_t *p, *c;
/* register flash specific commands */
@ -340,7 +341,6 @@ static int handle_flash_bank_command(struct command_context_s *cmd_ctx, char *cm
found = 1;
}
}
/* no matching flash driver found */
if (!found)
@ -367,8 +367,9 @@ static int handle_flash_info_command(struct command_context_s *cmd_ctx, char *cm
for (p = flash_banks; p; p = p->next, i++)
{
if (i == bank_nr)
{
if (i != bank_nr)
continue;
char buf[1024];
/* attempt auto probe */
@ -409,7 +410,6 @@ static int handle_flash_info_command(struct command_context_s *cmd_ctx, char *cm
if (retval != ERROR_OK)
LOG_ERROR("error retrieving flash info (%d)", retval);
}
}
return ERROR_OK;
}
@ -463,8 +463,6 @@ static int handle_flash_erase_check_command(struct command_context_s *cmd_ctx, c
if (ERROR_OK != retval)
return retval;
if (p)
{
int j;
if ((retval = p->driver->erase_check(p)) == ERROR_OK)
{
@ -495,7 +493,6 @@ static int handle_flash_erase_check_command(struct command_context_s *cmd_ctx, c
p->sectors[j].size >> 10,
erase_state);
}
}
return ERROR_OK;
}
@ -556,9 +553,6 @@ static int handle_flash_protect_check_command(struct command_context_s *cmd_ctx,
if (ERROR_OK != retval)
return retval;
if (p)
{
int retval;
if ((retval = p->driver->protect_check(p)) == ERROR_OK)
{
command_print(cmd_ctx, "successfully checked protect state");
@ -571,7 +565,6 @@ static int handle_flash_protect_check_command(struct command_context_s *cmd_ctx,
{
command_print(cmd_ctx, "unknown error when checking protection state of flash bank '#%s' at 0x%8.8" PRIx32, args[0], p->base);
}
}
return ERROR_OK;
}
@ -597,8 +590,9 @@ static int flash_check_sector_parameters(struct command_context_s *cmd_ctx,
static int handle_flash_erase_command(struct command_context_s *cmd_ctx,
char *cmd, char **args, int argc)
{
if (argc > 2)
{
if (argc != 2)
return ERROR_COMMAND_SYNTAX_ERROR;
uint32_t bank_nr;
uint32_t first;
uint32_t last;
@ -633,9 +627,6 @@ static int handle_flash_erase_command(struct command_context_s *cmd_ctx,
duration_text);
free(duration_text);
}
}
else
return ERROR_COMMAND_SYNTAX_ERROR;
return ERROR_OK;
}
@ -643,8 +634,9 @@ static int handle_flash_erase_command(struct command_context_s *cmd_ctx,
static int handle_flash_protect_command(struct command_context_s *cmd_ctx,
char *cmd, char **args, int argc)
{
if (argc > 3)
{
if (argc != 3)
return ERROR_COMMAND_SYNTAX_ERROR;
uint32_t bank_nr;
uint32_t first;
uint32_t last;
@ -680,9 +672,6 @@ static int handle_flash_protect_command(struct command_context_s *cmd_ctx,
(set) ? "set" : "cleared", (int) first,
(int) last, (int) bank_nr);
}
}
else
return ERROR_COMMAND_SYNTAX_ERROR;
return ERROR_OK;
}