Commit 464fb126 authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Ingo Molnar

efi/libstub/file: Merge file name buffers to reduce stack usage

Arnd reports that commit

  9302c1bb ("efi/libstub: Rewrite file I/O routine")

reworks the file I/O routines in a way that triggers the following
warning:

  drivers/firmware/efi/libstub/file.c:240:1: warning: the frame size
            of 1200 bytes is larger than 1024 bytes [-Wframe-larger-than=]

We can work around this issue dropping an instance of efi_char16_t[256]
from the stack frame, and reusing the 'filename' field of the file info
struct that we use to obtain file information from EFI (which contains
the file name even though we already know it since we used it to open
the file in the first place)
Reported-by: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20200409130434.6736-8-ardb@kernel.org
parent 8b84769a
...@@ -29,30 +29,31 @@ ...@@ -29,30 +29,31 @@
*/ */
#define EFI_READ_CHUNK_SIZE SZ_1M #define EFI_READ_CHUNK_SIZE SZ_1M
struct finfo {
efi_file_info_t info;
efi_char16_t filename[MAX_FILENAME_SIZE];
};
static efi_status_t efi_open_file(efi_file_protocol_t *volume, static efi_status_t efi_open_file(efi_file_protocol_t *volume,
efi_char16_t *filename_16, struct finfo *fi,
efi_file_protocol_t **handle, efi_file_protocol_t **handle,
unsigned long *file_size) unsigned long *file_size)
{ {
struct {
efi_file_info_t info;
efi_char16_t filename[MAX_FILENAME_SIZE];
} finfo;
efi_guid_t info_guid = EFI_FILE_INFO_ID; efi_guid_t info_guid = EFI_FILE_INFO_ID;
efi_file_protocol_t *fh; efi_file_protocol_t *fh;
unsigned long info_sz; unsigned long info_sz;
efi_status_t status; efi_status_t status;
status = volume->open(volume, &fh, filename_16, EFI_FILE_MODE_READ, 0); status = volume->open(volume, &fh, fi->filename, EFI_FILE_MODE_READ, 0);
if (status != EFI_SUCCESS) { if (status != EFI_SUCCESS) {
pr_efi_err("Failed to open file: "); pr_efi_err("Failed to open file: ");
efi_char16_printk(filename_16); efi_char16_printk(fi->filename);
efi_printk("\n"); efi_printk("\n");
return status; return status;
} }
info_sz = sizeof(finfo); info_sz = sizeof(struct finfo);
status = fh->get_info(fh, &info_guid, &info_sz, &finfo); status = fh->get_info(fh, &info_guid, &info_sz, fi);
if (status != EFI_SUCCESS) { if (status != EFI_SUCCESS) {
pr_efi_err("Failed to get file info\n"); pr_efi_err("Failed to get file info\n");
fh->close(fh); fh->close(fh);
...@@ -60,7 +61,7 @@ static efi_status_t efi_open_file(efi_file_protocol_t *volume, ...@@ -60,7 +61,7 @@ static efi_status_t efi_open_file(efi_file_protocol_t *volume,
} }
*handle = fh; *handle = fh;
*file_size = finfo.info.file_size; *file_size = fi->info.file_size;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
...@@ -146,13 +147,13 @@ static efi_status_t handle_cmdline_files(efi_loaded_image_t *image, ...@@ -146,13 +147,13 @@ static efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
alloc_addr = alloc_size = 0; alloc_addr = alloc_size = 0;
do { do {
efi_char16_t filename[MAX_FILENAME_SIZE]; struct finfo fi;
unsigned long size; unsigned long size;
void *addr; void *addr;
offset = find_file_option(cmdline, cmdline_len, offset = find_file_option(cmdline, cmdline_len,
optstr, optstr_size, optstr, optstr_size,
filename, ARRAY_SIZE(filename)); fi.filename, ARRAY_SIZE(fi.filename));
if (!offset) if (!offset)
break; break;
...@@ -166,7 +167,7 @@ static efi_status_t handle_cmdline_files(efi_loaded_image_t *image, ...@@ -166,7 +167,7 @@ static efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
return status; return status;
} }
status = efi_open_file(volume, filename, &file, &size); status = efi_open_file(volume, &fi, &file, &size);
if (status != EFI_SUCCESS) if (status != EFI_SUCCESS)
goto err_close_volume; goto err_close_volume;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment