1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-26 22:52:34 +02:00

Remove programmer_shutdown() from doit()

Because the programmer initialization that has to be called way
earlier and independently elsewhere, it does not make a lot of sense
to deinit within doit(). Also, free the logfile name at the end of
main() to catch more execution paths and because this moves it to
the other cleanup instructions.

Corresponding to flashrom svn r1788.

Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
This commit is contained in:
Stefan Tauner 2014-05-07 22:07:23 +00:00
parent f3607d191a
commit 20da4aa82c
2 changed files with 10 additions and 12 deletions

View File

@ -338,8 +338,7 @@ int main(int argc, char *argv[])
if (logfile && check_filename(logfile, "log")) if (logfile && check_filename(logfile, "log"))
cli_classic_abort_usage(); cli_classic_abort_usage();
if (logfile && open_logfile(logfile)) if (logfile && open_logfile(logfile))
return 1; cli_classic_abort_usage();
free(logfile);
#endif /* !STANDALONE */ #endif /* !STANDALONE */
#if CONFIG_PRINT_WIKI == 1 #if CONFIG_PRINT_WIKI == 1
@ -522,8 +521,6 @@ int main(int argc, char *argv[])
*/ */
programmer_delay(100000); programmer_delay(100000);
ret |= doit(fill_flash, force, filename, read_it, write_it, erase_it, verify_it); ret |= doit(fill_flash, force, filename, read_it, write_it, erase_it, verify_it);
/* Note: doit() already calls programmer_shutdown(). */
goto out;
out_shutdown: out_shutdown:
programmer_shutdown(); programmer_shutdown();
@ -539,6 +536,7 @@ out:
free((char *)chip_to_probe); /* Silence! Freeing is not modifying contents. */ free((char *)chip_to_probe); /* Silence! Freeing is not modifying contents. */
chip_to_probe = NULL; chip_to_probe = NULL;
#ifndef STANDALONE #ifndef STANDALONE
free(logfile);
ret |= close_logfile(); ret |= close_logfile();
#endif /* !STANDALONE */ #endif /* !STANDALONE */
return ret; return ret;

View File

@ -413,6 +413,11 @@ int programmer_init(enum programmer prog, const char *param)
return ret; return ret;
} }
/** Calls registered shutdown functions and resets internal programmer-related variables.
* Calling it is safe even without previous initialization, but further interactions with programmer support
* require a call to programmer_init() (afterwards).
*
* @return The OR-ed result values of all shutdown functions (i.e. 0 on success). */
int programmer_shutdown(void) int programmer_shutdown(void)
{ {
int ret = 0; int ret = 0;
@ -1913,14 +1918,12 @@ int doit(struct flashctx *flash, int force, const char *filename, int read_it,
if (chip_safety_check(flash, force, read_it, write_it, erase_it, verify_it)) { if (chip_safety_check(flash, force, read_it, write_it, erase_it, verify_it)) {
msg_cerr("Aborting.\n"); msg_cerr("Aborting.\n");
ret = 1; return 1;
goto out_nofree;
} }
if (normalize_romentries(flash)) { if (normalize_romentries(flash)) {
msg_cerr("Requested regions can not be handled. Aborting.\n"); msg_cerr("Requested regions can not be handled. Aborting.\n");
ret = 1; return 1;
goto out_nofree;
} }
/* Given the existence of read locks, we want to unlock for read, /* Given the existence of read locks, we want to unlock for read,
@ -1930,8 +1933,7 @@ int doit(struct flashctx *flash, int force, const char *filename, int read_it,
flash->chip->unlock(flash); flash->chip->unlock(flash);
if (read_it) { if (read_it) {
ret = read_flash_to_file(flash, filename); return read_flash_to_file(flash, filename);
goto out_nofree;
} }
oldcontents = malloc(size); oldcontents = malloc(size);
@ -2048,7 +2050,5 @@ int doit(struct flashctx *flash, int force, const char *filename, int read_it,
out: out:
free(oldcontents); free(oldcontents);
free(newcontents); free(newcontents);
out_nofree:
programmer_shutdown();
return ret; return ret;
} }