amdfwtool: Remove the function's dependency to ctx
This is for next CL to move the write_body to another source, handle_file.c. https://review.coreboot.org/c/coreboot/+/78305 Removing amdfwtool_cleanup in write_body will not change the result. Write_body returns to main and amdfwtool_cleanup still ends up getting called. Change-Id: I639828498fa45911f430500735e90ddc198b6af5 Signed-off-by: Zheng Bao <fishbaozi@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/78304 Reviewed-by: Felix Held <felix-coreboot@felixheld.de> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
@@ -1814,7 +1814,7 @@ static int set_efs_table(uint8_t soc_id, amd_cb_config *cb_config,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t write_body(char *output, void *body_offset, ssize_t body_size, context *ctx)
|
static ssize_t write_body(char *output, void *body_offset, ssize_t body_size)
|
||||||
{
|
{
|
||||||
char body_name[PATH_MAX], body_tmp_name[PATH_MAX];
|
char body_name[PATH_MAX], body_tmp_name[PATH_MAX];
|
||||||
int ret;
|
int ret;
|
||||||
@@ -1828,26 +1828,22 @@ static ssize_t write_body(char *output, void *body_offset, ssize_t body_size, co
|
|||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
fprintf(stderr, "Error %s forming BODY tmp file name: %d\n",
|
fprintf(stderr, "Error %s forming BODY tmp file name: %d\n",
|
||||||
strerror(errno), ret);
|
strerror(errno), ret);
|
||||||
amdfwtool_cleanup(ctx);
|
return -1;
|
||||||
exit(1);
|
|
||||||
} else if ((unsigned int)ret >= sizeof(body_tmp_name)) {
|
} else if ((unsigned int)ret >= sizeof(body_tmp_name)) {
|
||||||
fprintf(stderr, "BODY File name %d > %zu\n", ret, sizeof(body_tmp_name));
|
fprintf(stderr, "BODY File name %d > %zu\n", ret, sizeof(body_tmp_name));
|
||||||
amdfwtool_cleanup(ctx);
|
return -1;
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = open(body_tmp_name, O_RDWR | O_CREAT | O_TRUNC, 0666);
|
fd = open(body_tmp_name, O_RDWR | O_CREAT | O_TRUNC, 0666);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
fprintf(stderr, "Error: Opening %s file: %s\n", body_tmp_name, strerror(errno));
|
fprintf(stderr, "Error: Opening %s file: %s\n", body_tmp_name, strerror(errno));
|
||||||
amdfwtool_cleanup(ctx);
|
return -1;
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = write_from_buf_to_file(fd, body_offset, body_size);
|
bytes = write_from_buf_to_file(fd, body_offset, body_size);
|
||||||
if (bytes != body_size) {
|
if (bytes != body_size) {
|
||||||
fprintf(stderr, "Error: Writing to file %s failed\n", body_tmp_name);
|
fprintf(stderr, "Error: Writing to file %s failed\n", body_tmp_name);
|
||||||
amdfwtool_cleanup(ctx);
|
return -1;
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
@@ -1855,14 +1851,12 @@ static ssize_t write_body(char *output, void *body_offset, ssize_t body_size, co
|
|||||||
ret = snprintf(body_name, sizeof(body_name), "%s%s", output, BODY_FILE_SUFFIX);
|
ret = snprintf(body_name, sizeof(body_name), "%s%s", output, BODY_FILE_SUFFIX);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
fprintf(stderr, "Error %s forming BODY file name: %d\n", strerror(errno), ret);
|
fprintf(stderr, "Error %s forming BODY file name: %d\n", strerror(errno), ret);
|
||||||
amdfwtool_cleanup(ctx);
|
return -1;
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rename(body_tmp_name, body_name)) {
|
if (rename(body_tmp_name, body_name)) {
|
||||||
fprintf(stderr, "Error: renaming file %s to %s\n", body_tmp_name, body_name);
|
fprintf(stderr, "Error: renaming file %s to %s\n", body_tmp_name, body_name);
|
||||||
amdfwtool_cleanup(ctx);
|
return -1;
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return bytes;
|
return bytes;
|
||||||
@@ -2562,7 +2556,7 @@ int main(int argc, char **argv)
|
|||||||
ssize_t bytes;
|
ssize_t bytes;
|
||||||
|
|
||||||
bytes = write_body(output, BUFF_OFFSET(ctx, body_location),
|
bytes = write_body(output, BUFF_OFFSET(ctx, body_location),
|
||||||
ctx.current - body_location, &ctx);
|
ctx.current - body_location);
|
||||||
if (bytes != ctx.current - body_location) {
|
if (bytes != ctx.current - body_location) {
|
||||||
fprintf(stderr, "Error: Writing body\n");
|
fprintf(stderr, "Error: Writing body\n");
|
||||||
retval = 1;
|
retval = 1;
|
||||||
|
Reference in New Issue
Block a user