Skip to content

Commit 4e23c96

Browse files
committed
efi/libstub: Use __free() helper for pool deallocations
Annotate some local buffer allocations as __free(efi_pool) and simplify the associated error handling accordingly. This removes a couple of gotos and simplifies the code. Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
1 parent ad69b0b commit 4e23c96

File tree

3 files changed

+20
-26
lines changed

3 files changed

+20
-26
lines changed

drivers/firmware/efi/libstub/efi-stub-helper.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ bool __pure __efi_soft_reserve_enabled(void)
4747
*/
4848
efi_status_t efi_parse_options(char const *cmdline)
4949
{
50-
size_t len;
50+
char *buf __free(efi_pool) = NULL;
5151
efi_status_t status;
52-
char *str, *buf;
52+
size_t len;
53+
char *str;
5354

5455
if (!cmdline)
5556
return EFI_SUCCESS;
@@ -102,7 +103,6 @@ efi_status_t efi_parse_options(char const *cmdline)
102103
efi_parse_option_graphics(val + strlen("efifb:"));
103104
}
104105
}
105-
efi_bs_call(free_pool, buf);
106106
return EFI_SUCCESS;
107107
}
108108

@@ -250,7 +250,7 @@ static efi_status_t efi_measure_tagged_event(unsigned long load_addr,
250250
u64, const union efistub_event *);
251251
struct { u32 hash_log_extend_event; } mixed_mode;
252252
} method;
253-
struct efistub_measured_event *evt;
253+
struct efistub_measured_event *evt __free(efi_pool) = NULL;
254254
int size = struct_size(evt, tagged_event.tagged_event_data,
255255
events[event].event_data_len);
256256
efi_guid_t tcg2_guid = EFI_TCG2_PROTOCOL_GUID;
@@ -312,7 +312,6 @@ static efi_status_t efi_measure_tagged_event(unsigned long load_addr,
312312

313313
status = efi_fn_call(&method, hash_log_extend_event, protocol, 0,
314314
load_addr, load_size, &evt->event_data);
315-
efi_bs_call(free_pool, evt);
316315

317316
if (status == EFI_SUCCESS)
318317
return EFI_SUCCESS;

drivers/firmware/efi/libstub/efi-stub.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ static u32 get_supported_rt_services(void)
104104

105105
efi_status_t efi_handle_cmdline(efi_loaded_image_t *image, char **cmdline_ptr)
106106
{
107+
char *cmdline __free(efi_pool) = NULL;
107108
efi_status_t status;
108-
char *cmdline;
109109

110110
/*
111111
* Get the command line from EFI, using the LOADED_IMAGE
@@ -120,25 +120,24 @@ efi_status_t efi_handle_cmdline(efi_loaded_image_t *image, char **cmdline_ptr)
120120

121121
if (!IS_ENABLED(CONFIG_CMDLINE_FORCE)) {
122122
status = efi_parse_options(cmdline);
123-
if (status != EFI_SUCCESS)
124-
goto fail_free_cmdline;
123+
if (status != EFI_SUCCESS) {
124+
efi_err("Failed to parse EFI load options\n");
125+
return status;
126+
}
125127
}
126128

127129
if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) ||
128130
IS_ENABLED(CONFIG_CMDLINE_FORCE) ||
129131
cmdline[0] == 0) {
130132
status = efi_parse_options(CONFIG_CMDLINE);
131-
if (status != EFI_SUCCESS)
132-
goto fail_free_cmdline;
133+
if (status != EFI_SUCCESS) {
134+
efi_err("Failed to parse built-in command line\n");
135+
return status;
136+
}
133137
}
134138

135-
*cmdline_ptr = cmdline;
139+
*cmdline_ptr = no_free_ptr(cmdline);
136140
return EFI_SUCCESS;
137-
138-
fail_free_cmdline:
139-
efi_err("Failed to parse options\n");
140-
efi_bs_call(free_pool, cmdline);
141-
return status;
142141
}
143142

144143
efi_status_t efi_stub_common(efi_handle_t handle,

drivers/firmware/efi/libstub/x86-stub.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ union sev_memory_acceptance_protocol {
4242
static efi_status_t
4343
preserve_pci_rom_image(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom)
4444
{
45-
struct pci_setup_rom *rom = NULL;
45+
struct pci_setup_rom *rom __free(efi_pool) = NULL;
4646
efi_status_t status;
4747
unsigned long size;
4848
uint64_t romsize;
@@ -75,36 +75,32 @@ preserve_pci_rom_image(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom)
7575
rom->data.len = size - sizeof(struct setup_data);
7676
rom->data.next = 0;
7777
rom->pcilen = romsize;
78-
*__rom = rom;
7978

8079
status = efi_call_proto(pci, pci.read, EfiPciIoWidthUint16,
8180
PCI_VENDOR_ID, 1, &rom->vendor);
8281

8382
if (status != EFI_SUCCESS) {
8483
efi_err("Failed to read rom->vendor\n");
85-
goto free_struct;
84+
return status;
8685
}
8786

8887
status = efi_call_proto(pci, pci.read, EfiPciIoWidthUint16,
8988
PCI_DEVICE_ID, 1, &rom->devid);
9089

9190
if (status != EFI_SUCCESS) {
9291
efi_err("Failed to read rom->devid\n");
93-
goto free_struct;
92+
return status;
9493
}
9594

9695
status = efi_call_proto(pci, get_location, &rom->segment, &rom->bus,
9796
&rom->device, &rom->function);
9897

9998
if (status != EFI_SUCCESS)
100-
goto free_struct;
99+
return status;
101100

102101
memcpy(rom->romdata, romimage, romsize);
103-
return status;
104-
105-
free_struct:
106-
efi_bs_call(free_pool, rom);
107-
return status;
102+
*__rom = no_free_ptr(rom);
103+
return EFI_SUCCESS;
108104
}
109105

110106
/*

0 commit comments

Comments
 (0)