From: Lennart Poettering Date: Fri, 20 Mar 2026 21:07:51 +0000 (+0100) Subject: boot: switch initrd_register() to use _cleanup_free_ and other tweaks X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=587064b3f3417e4e7f66d577d7d1725e31b955f1;p=thirdparty%2Fsystemd.git boot: switch initrd_register() to use _cleanup_free_ and other tweaks --- diff --git a/src/boot/initrd.c b/src/boot/initrd.c index d8cbe7deed4..569b757be7a 100644 --- a/src/boot/initrd.c +++ b/src/boot/initrd.c @@ -1,5 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "efi-log.h" +#include "efi.h" #include "initrd.h" #include "iovec-util-fundamental.h" #include "proto/device-path.h" @@ -72,7 +74,6 @@ EFI_STATUS initrd_register( EFI_STATUS err; EFI_DEVICE_PATH *dp = (EFI_DEVICE_PATH *) &efi_initrd_device_path; EFI_HANDLE handle; - struct initrd_loader *loader; assert(ret_initrd_handle); @@ -82,15 +83,14 @@ EFI_STATUS initrd_register( if (!iovec_is_set(initrd)) return EFI_SUCCESS; - /* check if a LINUX_INITRD_MEDIA_GUID DevicePath is already registered. - LocateDevicePath checks for the "closest DevicePath" and returns its handle, - where as InstallMultipleProtocolInterfaces only matches identical DevicePaths. - */ + /* Check if a LINUX_INITRD_MEDIA_GUID DevicePath is already registered. LocateDevicePath checks for + * the "closest DevicePath" and returns its handle, whereas InstallMultipleProtocolInterfaces() only + * matches identical DevicePaths. */ err = BS->LocateDevicePath(MAKE_GUID_PTR(EFI_LOAD_FILE2_PROTOCOL), &dp, &handle); if (err != EFI_NOT_FOUND) /* InitrdMedia is already registered */ return EFI_ALREADY_STARTED; - loader = xnew(struct initrd_loader, 1); + _cleanup_free_ struct initrd_loader *loader = xnew(struct initrd_loader, 1); *loader = (struct initrd_loader) { .load_file.LoadFile = initrd_load_file, .data = *initrd, @@ -98,14 +98,17 @@ EFI_STATUS initrd_register( /* create a new handle and register the LoadFile2 protocol with the InitrdMediaPath on it */ err = BS->InstallMultipleProtocolInterfaces( - ret_initrd_handle, MAKE_GUID_PTR(EFI_DEVICE_PATH_PROTOCOL), - &efi_initrd_device_path, MAKE_GUID_PTR(EFI_LOAD_FILE2_PROTOCOL), - loader, - NULL); + ret_initrd_handle, + MAKE_GUID_PTR(EFI_DEVICE_PATH_PROTOCOL), &efi_initrd_device_path, + MAKE_GUID_PTR(EFI_LOAD_FILE2_PROTOCOL), loader, + /* sentinel= */ NULL); if (err != EFI_SUCCESS) - free(loader); + return log_debug_status(err, "Failed to install new initrd device: %m"); + + log_debug("Installed new initrd of size %zu.", loader->data.iov_len); - return err; + TAKE_PTR(loader); + return EFI_SUCCESS; } EFI_STATUS initrd_unregister(EFI_HANDLE initrd_handle) {