]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: introduce common shortcut exit path in pack_cpio()
authorLennart Poettering <lennart@poettering.net>
Tue, 26 Jul 2022 16:23:49 +0000 (18:23 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 27 Jul 2022 08:29:08 +0000 (09:29 +0100)
THis will be useful in a later commit, when we add more stuff to the
common exit path. But even without that, it's a nice simplification,
removing redundant lines.

src/boot/efi/cpio.c

index ad469af034ddd2b1d70c3cb131f9f36b6142ab00..6905e07c851c6d841a5e25799cb6fc8464190236 100644 (file)
@@ -332,20 +332,14 @@ EFI_STATUS pack_cpio(
         assert(ret_buffer);
         assert(ret_buffer_size);
 
-        if (!loaded_image->DeviceHandle) {
-                *ret_buffer = NULL;
-                *ret_buffer_size = 0;
-                return EFI_SUCCESS;
-        }
+        if (!loaded_image->DeviceHandle)
+                goto nothing;
 
         err = open_volume(loaded_image->DeviceHandle, &root);
-        if (err == EFI_UNSUPPORTED) {
+        if (err == EFI_UNSUPPORTED)
                 /* Error will be unsupported if the bootloader doesn't implement the file system protocol on
                  * its file handles. */
-                *ret_buffer = NULL;
-                *ret_buffer_size = 0;
-                return EFI_SUCCESS;
-        }
+                goto nothing;
         if (err != EFI_SUCCESS)
                 return log_error_status_stall(
                                 err, L"Unable to open root directory: %r", err);
@@ -354,12 +348,9 @@ EFI_STATUS pack_cpio(
                 dropin_dir = rel_dropin_dir = xpool_print(L"%D.extra.d", loaded_image->FilePath);
 
         err = open_directory(root, dropin_dir, &extra_dir);
-        if (err == EFI_NOT_FOUND) {
+        if (err == EFI_NOT_FOUND)
                 /* No extra subdir, that's totally OK */
-                *ret_buffer = NULL;
-                *ret_buffer_size = 0;
-                return EFI_SUCCESS;
-        }
+                goto nothing;
         if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Failed to open extra directory of loaded image: %r", err);
 
@@ -401,12 +392,9 @@ EFI_STATUS pack_cpio(
                 items[n_items] = NULL; /* Let's always NUL terminate, to make freeing via strv_free() easy */
         }
 
-        if (n_items == 0) {
+        if (n_items == 0)
                 /* Empty directory */
-                *ret_buffer = NULL;
-                *ret_buffer_size = 0;
-                return EFI_SUCCESS;
-        }
+                goto nothing;
 
         /* Now, sort the files we found, to make this uniform and stable (and to ensure the TPM measurements
          * are not dependent on read order) */
@@ -456,5 +444,11 @@ EFI_STATUS pack_cpio(
         *ret_buffer = TAKE_PTR(buffer);
         *ret_buffer_size = buffer_size;
 
+        return EFI_SUCCESS;
+
+nothing:
+        *ret_buffer = NULL;
+        *ret_buffer_size = 0;
+
         return EFI_SUCCESS;
 }