Attention is currently required from: Zheng Bao. Hello Zheng Bao,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/coreboot/+/51881
to review the following change.
Change subject: amdfwtool: Add a function to make the calling stack less deep ......................................................................
amdfwtool: Add a function to make the calling stack less deep
Change-Id: Ib8cae386eace4f423bde9c252992625e1ff3c690 Signed-off-by: Zheng Bao fishbaozi@gmail.com --- M util/amdfwtool/data_parse.c 1 file changed, 33 insertions(+), 22 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/81/51881/1
diff --git a/util/amdfwtool/data_parse.c b/util/amdfwtool/data_parse.c index 28807fc..4b84d636 100644 --- a/util/amdfwtool/data_parse.c +++ b/util/amdfwtool/data_parse.c @@ -392,6 +392,33 @@ return retval; }
+static uint8_t process_one_line(char *fw_type_str, char *value) +{ + char *path_filename; + + path_filename = malloc(MAX_LINE_SIZE); + strcpy(path_filename, fw_dir); + strcat(path_filename, "/"); + strcat(path_filename, value); + + if (find_register_fw_filename_psp_dir( + fw_type_str, path_filename) == 0) { + if (find_register_fw_filename_bios_dir( + fw_type_str, path_filename) == 0) { + fprintf(stderr, "Module's name "%s" is not valid\n", fw_type_str); + return 0; /* Stop parsing. */ + } else { + if (list_deps) + printf(" %s ", path_filename); + } + } else { + if (list_deps) + printf(" %s ", path_filename); + } + + return 1; +} + #define N_MATCHES 4 /* return value: @@ -400,8 +427,9 @@ */ uint8_t process_config(FILE *config) { - char oneline[MAX_LINE_SIZE], *path_filename; + char oneline[MAX_LINE_SIZE]; regmatch_t match[N_MATCHES]; + uint8_t ret_val;
compile_reg_expr(REG_EXTENDED | REG_NEWLINE, blank_or_comment_regex, &blank_or_comment_expr); @@ -437,27 +465,10 @@ if (strcmp(&(oneline[match[1].rm_so]), "FIRMWARE_LOCATION") == 0) { continue; } else { - path_filename = malloc(MAX_LINE_SIZE); - strcpy(path_filename, fw_dir); - strcat(path_filename, "/"); - strcat(path_filename, &(oneline[match[2].rm_so])); - - if (find_register_fw_filename_psp_dir( - &(oneline[match[1].rm_so]), - path_filename) == 0) { - if (find_register_fw_filename_bios_dir( - &(oneline[match[1].rm_so]), - path_filename) == 0) { - fprintf(stderr, "Module's name "%s" is not valid\n", oneline); - return 0; /* Stop parsing. */ - } else { - if (list_deps) - printf(" %s ", path_filename); - } - } else { - if (list_deps) - printf(" %s ", path_filename); - } + ret_val = process_one_line(&(oneline[match[1].rm_so]), + &(oneline[match[2].rm_so])); + if (ret_val == 0) + return 0; } } else { fprintf(stderr, "AMDFWTOOL config file line can't be parsed "%s"\n", oneline);