Skip to content

Commit 464fb12

Browse files
ardbiesheuvelIngo Molnar
authored andcommitted
efi/libstub/file: Merge file name buffers to reduce stack usage
Arnd reports that commit 9302c1b ("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: Arnd Bergmann <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 8b84769 commit 464fb12

File tree

1 file changed

+14
-13
lines changed
  • drivers/firmware/efi/libstub

1 file changed

+14
-13
lines changed

drivers/firmware/efi/libstub/file.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,38 +29,39 @@
2929
*/
3030
#define EFI_READ_CHUNK_SIZE SZ_1M
3131

32+
struct finfo {
33+
efi_file_info_t info;
34+
efi_char16_t filename[MAX_FILENAME_SIZE];
35+
};
36+
3237
static efi_status_t efi_open_file(efi_file_protocol_t *volume,
33-
efi_char16_t *filename_16,
38+
struct finfo *fi,
3439
efi_file_protocol_t **handle,
3540
unsigned long *file_size)
3641
{
37-
struct {
38-
efi_file_info_t info;
39-
efi_char16_t filename[MAX_FILENAME_SIZE];
40-
} finfo;
4142
efi_guid_t info_guid = EFI_FILE_INFO_ID;
4243
efi_file_protocol_t *fh;
4344
unsigned long info_sz;
4445
efi_status_t status;
4546

46-
status = volume->open(volume, &fh, filename_16, EFI_FILE_MODE_READ, 0);
47+
status = volume->open(volume, &fh, fi->filename, EFI_FILE_MODE_READ, 0);
4748
if (status != EFI_SUCCESS) {
4849
pr_efi_err("Failed to open file: ");
49-
efi_char16_printk(filename_16);
50+
efi_char16_printk(fi->filename);
5051
efi_printk("\n");
5152
return status;
5253
}
5354

54-
info_sz = sizeof(finfo);
55-
status = fh->get_info(fh, &info_guid, &info_sz, &finfo);
55+
info_sz = sizeof(struct finfo);
56+
status = fh->get_info(fh, &info_guid, &info_sz, fi);
5657
if (status != EFI_SUCCESS) {
5758
pr_efi_err("Failed to get file info\n");
5859
fh->close(fh);
5960
return status;
6061
}
6162

6263
*handle = fh;
63-
*file_size = finfo.info.file_size;
64+
*file_size = fi->info.file_size;
6465
return EFI_SUCCESS;
6566
}
6667

@@ -146,13 +147,13 @@ static efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
146147

147148
alloc_addr = alloc_size = 0;
148149
do {
149-
efi_char16_t filename[MAX_FILENAME_SIZE];
150+
struct finfo fi;
150151
unsigned long size;
151152
void *addr;
152153

153154
offset = find_file_option(cmdline, cmdline_len,
154155
optstr, optstr_size,
155-
filename, ARRAY_SIZE(filename));
156+
fi.filename, ARRAY_SIZE(fi.filename));
156157

157158
if (!offset)
158159
break;
@@ -166,7 +167,7 @@ static efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
166167
return status;
167168
}
168169

169-
status = efi_open_file(volume, filename, &file, &size);
170+
status = efi_open_file(volume, &fi, &file, &size);
170171
if (status != EFI_SUCCESS)
171172
goto err_close_volume;
172173

0 commit comments

Comments
 (0)