1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-27 18:55:40 +03:00

Merge pull request #22111 from medhefgo/boot-cleanup

boot: Cleanup
This commit is contained in:
Luca Boccassi 2022-01-13 22:50:52 +00:00 committed by GitHub
commit e6d692ddfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 44 additions and 49 deletions

View File

@ -1309,12 +1309,9 @@ good:
entry->next_name = xpool_print(L"%s+%u-%u%s", prefix, next_left, next_done, suffix ?: L"");
}
static void config_entry_bump_counters(
ConfigEntry *entry,
EFI_FILE_HANDLE root_dir) {
static void config_entry_bump_counters(ConfigEntry *entry, EFI_FILE *root_dir) {
_cleanup_freepool_ CHAR16* old_path = NULL, *new_path = NULL;
_cleanup_(file_handle_closep) EFI_FILE_HANDLE handle = NULL;
_cleanup_(file_closep) EFI_FILE *handle = NULL;
_cleanup_freepool_ EFI_FILE_INFO *file_info = NULL;
UINTN file_info_size;
EFI_STATUS err;
@ -1375,7 +1372,6 @@ static void config_entry_add_from_file(
UINTN pos = 0;
CHAR8 *key, *value;
EFI_STATUS err;
EFI_FILE_HANDLE handle;
_cleanup_freepool_ CHAR16 *initrd = NULL;
assert(config);
@ -1483,10 +1479,10 @@ static void config_entry_add_from_file(
return;
/* check existence */
_cleanup_(file_closep) EFI_FILE *handle = NULL;
err = root_dir->Open(root_dir, &handle, entry->loader, EFI_FILE_MODE_READ, 0ULL);
if (EFI_ERROR(err))
return;
handle->Close(handle);
/* add initrd= to options */
if (entry->type == LOADER_LINUX && initrd) {
@ -1571,7 +1567,7 @@ static void config_load_entries(
EFI_FILE *root_dir,
const CHAR16 *loaded_image_path) {
_cleanup_(file_handle_closep) EFI_FILE_HANDLE entries_dir = NULL;
_cleanup_(file_closep) EFI_FILE *entries_dir = NULL;
_cleanup_freepool_ EFI_FILE_INFO *f = NULL;
UINTN f_size = 0;
EFI_STATUS err;
@ -1888,9 +1884,6 @@ static ConfigEntry *config_entry_add_loader_auto(
const CHAR16 *title,
const CHAR16 *loader) {
EFI_FILE_HANDLE handle;
EFI_STATUS err;
assert(config);
assert(device);
assert(root_dir);
@ -1916,10 +1909,10 @@ static ConfigEntry *config_entry_add_loader_auto(
}
/* check existence */
err = root_dir->Open(root_dir, &handle, (CHAR16*) loader, EFI_FILE_MODE_READ, 0ULL);
_cleanup_(file_closep) EFI_FILE *handle = NULL;
EFI_STATUS err = root_dir->Open(root_dir, &handle, (CHAR16*) loader, EFI_FILE_MODE_READ, 0ULL);
if (EFI_ERROR(err))
return NULL;
handle->Close(handle);
return config_entry_add_loader(config, device, LOADER_AUTO, id, key, title, loader, NULL);
}
@ -1939,7 +1932,7 @@ static void config_entry_add_osx(Config *config) {
return;
for (UINTN i = 0; i < n_handles; i++) {
_cleanup_(file_handle_closep) EFI_FILE *root = LibOpenRoot(handles[i]);
_cleanup_(file_closep) EFI_FILE *root = LibOpenRoot(handles[i]);
if (!root)
continue;
@ -2066,7 +2059,7 @@ static void config_entry_add_linux(
EFI_HANDLE *device,
EFI_FILE *root_dir) {
_cleanup_(file_handle_closep) EFI_FILE_HANDLE linux_dir = NULL;
_cleanup_(file_closep) EFI_FILE *linux_dir = NULL;
_cleanup_freepool_ EFI_FILE_INFO *f = NULL;
ConfigEntry *entry;
UINTN f_size = 0;
@ -2224,7 +2217,7 @@ static void config_load_xbootldr(
Config *config,
EFI_HANDLE *device) {
_cleanup_(file_handle_closep) EFI_FILE *root_dir = NULL;
_cleanup_(file_closep) EFI_FILE *root_dir = NULL;
EFI_HANDLE new_device;
EFI_STATUS err;
@ -2240,7 +2233,7 @@ static void config_load_xbootldr(
}
static EFI_STATUS image_start(
EFI_FILE_HANDLE root_dir,
EFI_FILE *root_dir,
EFI_HANDLE parent_image,
const Config *config,
const ConfigEntry *entry) {
@ -2455,8 +2448,8 @@ static void config_load_all_entries(
}
EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
_cleanup_freepool_ EFI_LOADED_IMAGE *loaded_image = NULL;
_cleanup_(file_handle_closep) EFI_FILE *root_dir = NULL;
EFI_LOADED_IMAGE *loaded_image;
_cleanup_(file_closep) EFI_FILE *root_dir = NULL;
_cleanup_(config_free) Config config = {};
CHAR16 *loaded_image_path;
EFI_STATUS err;

View File

@ -316,7 +316,7 @@ EFI_STATUS pack_cpio(
void **ret_buffer,
UINTN *ret_buffer_size) {
_cleanup_(file_handle_closep) EFI_FILE_HANDLE root = NULL, extra_dir = NULL;
_cleanup_(file_closep) EFI_FILE *root = NULL, *extra_dir = NULL;
UINTN dirent_size = 0, buffer_size = 0, n_items = 0, n_allocated = 0;
_cleanup_freepool_ CHAR16 *rel_dropin_dir = NULL;
_cleanup_freepool_ EFI_FILE_INFO *dirent = NULL;

View File

@ -64,9 +64,8 @@ static EFI_STATUS devicetree_fixup(struct devicetree_state *state, UINTN len) {
return err;
}
EFI_STATUS devicetree_install(struct devicetree_state *state,
EFI_FILE_HANDLE root_dir, CHAR16 *name) {
_cleanup_(file_handle_closep) EFI_FILE_HANDLE handle = NULL;
EFI_STATUS devicetree_install(struct devicetree_state *state, EFI_FILE *root_dir, CHAR16 *name) {
_cleanup_(file_closep) EFI_FILE *handle = NULL;
_cleanup_freepool_ EFI_FILE_INFO *info = NULL;
UINTN len;
EFI_STATUS err;

View File

@ -7,7 +7,7 @@ struct devicetree_state {
void *orig;
};
EFI_STATUS devicetree_install(struct devicetree_state *state, EFI_FILE_HANDLE root_dir, CHAR16 *name);
EFI_STATUS devicetree_install(struct devicetree_state *state, EFI_FILE *root_dir, CHAR16 *name);
EFI_STATUS devicetree_install_from_memory(
struct devicetree_state *state, const VOID *dtb_buffer, UINTN dtb_length);
void devicetree_cleanup(struct devicetree_state *state);

View File

@ -80,9 +80,9 @@ static EFI_STATUS reconnect(void) {
EFI_STATUS load_drivers(
EFI_HANDLE parent_image,
EFI_LOADED_IMAGE *loaded_image,
EFI_FILE_HANDLE root_dir) {
EFI_FILE *root_dir) {
_cleanup_(file_handle_closep) EFI_FILE_HANDLE drivers_dir = NULL;
_cleanup_(file_closep) EFI_FILE *drivers_dir = NULL;
_cleanup_freepool_ EFI_FILE_INFO *dirent = NULL;
UINTN dirent_size = 0, n_succeeded = 0;
EFI_STATUS err;

View File

@ -6,4 +6,4 @@
EFI_STATUS load_drivers(
EFI_HANDLE parent_image,
EFI_LOADED_IMAGE *loaded_image,
EFI_FILE_HANDLE root_dir);
EFI_FILE *root_dir);

View File

@ -224,7 +224,7 @@ EFI_STATUS pe_file_locate_sections(
UINTN *offsets,
UINTN *sizes) {
_cleanup_freepool_ struct PeSectionHeader *section_table = NULL;
_cleanup_(file_handle_closep) EFI_FILE_HANDLE handle = NULL;
_cleanup_(file_closep) EFI_FILE *handle = NULL;
struct DosFileHeader dos;
struct PeFileHeader pe;
UINTN len, section_table_len;

View File

@ -225,7 +225,7 @@ static void validate_sha256(void) {
EFI_STATUS process_random_seed(EFI_FILE *root_dir, RandomSeedMode mode) {
_cleanup_freepool_ void *seed = NULL, *new_seed = NULL, *rng = NULL, *for_kernel = NULL, *system_token = NULL;
_cleanup_(file_handle_closep) EFI_FILE_HANDLE handle = NULL;
_cleanup_(file_closep) EFI_FILE *handle = NULL;
UINTN size, rsize, wsize, system_token_size = 0;
_cleanup_freepool_ EFI_FILE_INFO *info = NULL;
EFI_STATUS err;

View File

@ -105,7 +105,6 @@ static EFIAPI EFI_STATUS security_policy_authentication (const EFI_SECURITY_PROT
_cleanup_freepool_ EFI_DEVICE_PATH *dev_path = NULL;
_cleanup_freepool_ CHAR16 *dev_path_str = NULL;
EFI_HANDLE h;
EFI_FILE *root;
_cleanup_freepool_ CHAR8 *file_buffer = NULL;
UINTN file_size;
@ -118,20 +117,22 @@ static EFIAPI EFI_STATUS security_policy_authentication (const EFI_SECURITY_PROT
if (!dev_path)
return EFI_OUT_OF_RESOURCES;
status = BS->LocateDevicePath(&FileSystemProtocol, &dev_path, &h);
EFI_DEVICE_PATH *dp = dev_path;
status = BS->LocateDevicePath(&FileSystemProtocol, &dp, &h);
if (EFI_ERROR(status))
return status;
/* No need to check return value, this already happened in efi_main() */
root = LibOpenRoot(h);
dev_path_str = DevicePathToStr(dev_path);
_cleanup_(file_closep) EFI_FILE *root = LibOpenRoot(h);
if (!root)
return EFI_NOT_FOUND;
dev_path_str = DevicePathToStr(dp);
if (!dev_path_str)
return EFI_OUT_OF_RESOURCES;
status = file_read(root, dev_path_str, 0, 0, &file_buffer, &file_size);
if (EFI_ERROR(status))
return status;
root->Close(root);
if (shim_validate(file_buffer, file_size))
return EFI_SUCCESS;

View File

@ -435,11 +435,12 @@ CHAR8 *strchra(const CHAR8 *s, CHAR8 c) {
return NULL;
}
EFI_STATUS file_read(EFI_FILE_HANDLE dir, const CHAR16 *name, UINTN off, UINTN size, CHAR8 **ret, UINTN *ret_size) {
_cleanup_(file_handle_closep) EFI_FILE_HANDLE handle = NULL;
EFI_STATUS file_read(EFI_FILE *dir, const CHAR16 *name, UINTN off, UINTN size, CHAR8 **ret, UINTN *ret_size) {
_cleanup_(file_closep) EFI_FILE *handle = NULL;
_cleanup_freepool_ CHAR8 *buf = NULL;
EFI_STATUS err;
assert(dir);
assert(name);
assert(ret);
@ -544,7 +545,7 @@ void sort_pointer_array(
}
EFI_STATUS get_file_info_harder(
EFI_FILE_HANDLE handle,
EFI_FILE *handle,
EFI_FILE_INFO **ret,
UINTN *ret_size) {
@ -577,7 +578,7 @@ EFI_STATUS get_file_info_harder(
}
EFI_STATUS readdir_harder(
EFI_FILE_HANDLE handle,
EFI_FILE *handle,
EFI_FILE_INFO **buffer,
UINTN *buffer_size) {
@ -700,11 +701,11 @@ CHAR16 **strv_free(CHAR16 **v) {
}
EFI_STATUS open_directory(
EFI_FILE_HANDLE root,
EFI_FILE *root,
const CHAR16 *path,
EFI_FILE_HANDLE *ret) {
EFI_FILE **ret) {
_cleanup_(file_handle_closep) EFI_FILE_HANDLE dir = NULL;
_cleanup_(file_closep) EFI_FILE *dir = NULL;
_cleanup_freepool_ EFI_FILE_INFO *file_info = NULL;
EFI_STATUS err;

View File

@ -71,7 +71,7 @@ CHAR8 *strchra(const CHAR8 *s, CHAR8 c);
CHAR16 *xstra_to_path(const CHAR8 *stra);
CHAR16 *xstra_to_str(const CHAR8 *stra);
EFI_STATUS file_read(EFI_FILE_HANDLE dir, const CHAR16 *name, UINTN off, UINTN size, CHAR8 **content, UINTN *content_size);
EFI_STATUS file_read(EFI_FILE *dir, const CHAR16 *name, UINTN off, UINTN size, CHAR8 **content, UINTN *content_size);
static inline void free_poolp(void *p) {
void *q = *(void**) p;
@ -79,12 +79,12 @@ static inline void free_poolp(void *p) {
if (!q)
return;
FreePool(q);
(void) BS->FreePool(q);
}
#define _cleanup_freepool_ _cleanup_(free_poolp)
static inline void file_handle_closep(EFI_FILE_HANDLE *handle) {
static inline void file_closep(EFI_FILE **handle) {
if (!*handle)
return;
@ -117,9 +117,9 @@ void clear_screen(UINTN attr);
typedef INTN (*compare_pointer_func_t)(const void *a, const void *b);
void sort_pointer_array(void **array, UINTN n_members, compare_pointer_func_t compare);
EFI_STATUS get_file_info_harder(EFI_FILE_HANDLE handle, EFI_FILE_INFO **ret, UINTN *ret_size);
EFI_STATUS get_file_info_harder(EFI_FILE *handle, EFI_FILE_INFO **ret, UINTN *ret_size);
EFI_STATUS readdir_harder(EFI_FILE_HANDLE handle, EFI_FILE_INFO **buffer, UINTN *buffer_size);
EFI_STATUS readdir_harder(EFI_FILE *handle, EFI_FILE_INFO **buffer, UINTN *buffer_size);
UINTN strnlena(const CHAR8 *p, UINTN maxlen);
CHAR8 *xstrndup8(const CHAR8 *p, UINTN sz);
@ -136,7 +136,7 @@ static inline void strv_freep(CHAR16 ***p) {
strv_free(*p);
}
EFI_STATUS open_directory(EFI_FILE_HANDLE root_dir, const CHAR16 *path, EFI_FILE_HANDLE *ret);
EFI_STATUS open_directory(EFI_FILE *root_dir, const CHAR16 *path, EFI_FILE **ret);
/* Conversion between EFI_PHYSICAL_ADDRESS and pointers is not obvious. The former is always 64bit, even on
* 32bit archs. And gcc complains if we cast a pointer to an integer of a different size. Hence let's do the

View File

@ -286,7 +286,8 @@ EFI_STATUS xbootldr_open(EFI_HANDLE *device, EFI_HANDLE *ret_device, EFI_FILE **
hd->SignatureType = SIGNATURE_TYPE_GUID;
}
err = BS->LocateDevicePath(&BlockIoProtocol, &partition_path, &new_device);
EFI_DEVICE_PATH *dp = partition_path;
err = BS->LocateDevicePath(&BlockIoProtocol, &dp, &new_device);
if (EFI_ERROR(err))
return err;