diff options
-rw-r--r-- | futility/updater.c | 21 | ||||
-rw-r--r-- | futility/updater.h | 2 | ||||
-rw-r--r-- | futility/updater_quirks.c | 25 |
3 files changed, 18 insertions, 30 deletions
diff --git a/futility/updater.c b/futility/updater.c index e1ae0769..e52f27f7 100644 --- a/futility/updater.c +++ b/futility/updater.c @@ -283,15 +283,9 @@ static int host_flashrom(enum flashrom_ops op, const char *image_path, } /* TODO(hungte) In future we should link with flashrom directly. */ - r = asprintf(&command, "flashrom %s %s -p %s %s %s %s %s", op_cmd, - image_path, programmer, dash_i, section_name, ignore_lock, - postfix); - - if (r == -1) { - /* `command` will be not available. */ - ERROR("Cannot allocate memory for command to execute."); - return -1; - } + ASPRINTF(&command, "flashrom %s %s -p %s %s %s %s %s", op_cmd, + image_path, programmer, dash_i, section_name, ignore_lock, + postfix); if (verbose) printf("Executing: %s\n", command); @@ -1244,12 +1238,9 @@ static int cbfs_file_exists(const char *image_file, char *cmd; int r; - if (asprintf(&cmd, - "cbfstool '%s' print -r %s 2>/dev/null | grep -q '^%s '", - image_file, section_name, cbfs_entry_name) < 0) { - ERROR("Failed to allocate buffer."); - return 0; - } + ASPRINTF(&cmd, + "cbfstool '%s' print -r %s 2>/dev/null | grep -q '^%s '", + image_file, section_name, cbfs_entry_name); r = system(cmd); free(cmd); return !r; diff --git a/futility/updater.h b/futility/updater.h index 3993f073..b315f2ed 100644 --- a/futility/updater.h +++ b/futility/updater.h @@ -17,6 +17,8 @@ extern int debugging_enabled; "DEBUG: %s: " format "\n", __FUNCTION__, ##__VA_ARGS__); } while (0) #define ERROR(format, ...) fprintf(stderr, \ "ERROR: %s: " format "\n", __FUNCTION__, ##__VA_ARGS__) +#define ASPRINTF(strp, ...) do { if (asprintf(strp, __VA_ARGS__) >= 0) break; \ + ERROR("Failed to allocate memory, abort."); exit(1); } while (0) /* FMAP section names. */ static const char * const FMAP_RO_FRID = "RO_FRID", diff --git a/futility/updater_quirks.c b/futility/updater_quirks.c index f3989e78..f625a74c 100644 --- a/futility/updater_quirks.c +++ b/futility/updater_quirks.c @@ -237,12 +237,10 @@ static const char *extract_cbfs_file(struct updater_config *cfg, const char *output = create_temp_file(cfg); char *command, *result; - if (asprintf(&command, "cbfstool \"%s\" extract -r %s -n \"%s\" " - "-f \"%s\" 2>&1", image_file, cbfs_region, - cbfs_name, output) < 0) { - ERROR("Failed to allocate internal buffer."); - return NULL; - } + ASPRINTF(&command, "cbfstool \"%s\" extract -r %s -n \"%s\" " + "-f \"%s\" 2>&1", image_file, cbfs_region, + cbfs_name, output); + result = host_shell(command); free(command); @@ -285,15 +283,12 @@ static int quirk_eve_smm_store(struct updater_config *cfg) return -1; /* crosreview.com/1165109: The offset is fixed at 0x1bf000. */ - if (asprintf(&command, - "cbfstool \"%s\" remove -r %s -n \"%s\" 2>/dev/null; " - "cbfstool \"%s\" add -r %s -n \"%s\" -f \"%s\" " - " -t raw -b 0x1bf000", temp_image, FMAP_RW_LEGACY, - smm_store_name, temp_image, FMAP_RW_LEGACY, - smm_store_name, old_store) < 0) { - ERROR("Failed to allocate internal buffer."); - return -1; - } + ASPRINTF(&command, + "cbfstool \"%s\" remove -r %s -n \"%s\" 2>/dev/null; " + "cbfstool \"%s\" add -r %s -n \"%s\" -f \"%s\" " + " -t raw -b 0x1bf000", temp_image, FMAP_RW_LEGACY, + smm_store_name, temp_image, FMAP_RW_LEGACY, + smm_store_name, old_store); host_shell(command); free(command); |