]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
gpt-auto-generator: use RET_GATHER, return first error
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 9 Jul 2023 19:33:50 +0000 (13:33 -0600)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 13 Jul 2023 09:40:15 +0000 (11:40 +0200)
src/gpt-auto-generator/gpt-auto-generator.c

index 08338bdd93dca9eb7b9f3dc7f56062a6b705dad1..cbd430ab5837ab5e970ae80bf1c8785e92f718fd 100644 (file)
@@ -753,7 +753,7 @@ static int add_root_mount(void) {
 
 static int process_loader_partitions(DissectedPartition *esp, DissectedPartition *xbootldr) {
         sd_id128_t loader_uuid;
-        int r, ret = 0;
+        int r;
 
         assert(esp);
         assert(xbootldr);
@@ -787,26 +787,21 @@ static int process_loader_partitions(DissectedPartition *esp, DissectedPartition
         return 0;
 
 mount:
-        if (xbootldr->found) {
-                r = add_partition_xbootldr(xbootldr);
-                if (r < 0)
-                        ret = r;
-        }
+        r = 0;
 
-        if (esp->found) {
-                r = add_partition_esp(esp, xbootldr->found);
-                if (r < 0)
-                        ret = r;
-        }
+        if (xbootldr->found)
+                RET_GATHER(r, add_partition_xbootldr(xbootldr));
+        if (esp->found)
+                RET_GATHER(r, add_partition_esp(esp, xbootldr->found));
 
-        return ret;
+        return r;
 }
 
 static int enumerate_partitions(dev_t devnum) {
         _cleanup_(dissected_image_unrefp) DissectedImage *m = NULL;
         _cleanup_(loop_device_unrefp) LoopDevice *loop = NULL;
         _cleanup_free_ char *devname = NULL;
-        int r, k;
+        int r;
 
         r = block_get_whole_disk(devnum, &devnum);
         if (r < 0)
@@ -846,45 +841,29 @@ static int enumerate_partitions(dev_t devnum) {
                 return ok ? 0 : r;
         }
 
-        if (m->partitions[PARTITION_SWAP].found) {
-                k = add_partition_swap(m->partitions + PARTITION_SWAP);
-                if (k < 0)
-                        r = k;
-        }
+        if (m->partitions[PARTITION_SWAP].found)
+                RET_GATHER(r, add_partition_swap(m->partitions + PARTITION_SWAP));
 
-        k = process_loader_partitions(m->partitions + PARTITION_ESP, m->partitions + PARTITION_XBOOTLDR);
-        if (k < 0)
-                r = k;
+        RET_GATHER(r, process_loader_partitions(m->partitions + PARTITION_ESP, m->partitions + PARTITION_XBOOTLDR));
 
-        if (m->partitions[PARTITION_HOME].found) {
-                k = add_partition_mount(PARTITION_HOME, m->partitions + PARTITION_HOME, "home", "/home", "Home Partition");
-                if (k < 0)
-                        r = k;
-        }
+        if (m->partitions[PARTITION_HOME].found)
+                RET_GATHER(r, add_partition_mount(PARTITION_HOME, m->partitions + PARTITION_HOME,
+                                                  "home", "/home", "Home Partition"));
 
-        if (m->partitions[PARTITION_SRV].found) {
-                k = add_partition_mount(PARTITION_SRV, m->partitions + PARTITION_SRV, "srv", "/srv", "Server Data Partition");
-                if (k < 0)
-                        r = k;
-        }
+        if (m->partitions[PARTITION_SRV].found)
+                RET_GATHER(r, add_partition_mount(PARTITION_SRV, m->partitions + PARTITION_SRV,
+                                                  "srv", "/srv", "Server Data Partition"));
 
-        if (m->partitions[PARTITION_VAR].found) {
-                k = add_partition_mount(PARTITION_VAR, m->partitions + PARTITION_VAR, "var", "/var", "Variable Data Partition");
-                if (k < 0)
-                        r = k;
-        }
+        if (m->partitions[PARTITION_VAR].found)
+                RET_GATHER(r, add_partition_mount(PARTITION_VAR, m->partitions + PARTITION_VAR,
+                                                  "var", "/var", "Variable Data Partition"));
 
-        if (m->partitions[PARTITION_TMP].found) {
-                k = add_partition_mount(PARTITION_TMP, m->partitions + PARTITION_TMP, "var-tmp", "/var/tmp", "Temporary Data Partition");
-                if (k < 0)
-                        r = k;
-        }
+        if (m->partitions[PARTITION_TMP].found)
+                RET_GATHER(r, add_partition_mount(PARTITION_TMP, m->partitions + PARTITION_TMP,
+                                                  "var-tmp", "/var/tmp", "Temporary Data Partition"));
 
-        if (m->partitions[PARTITION_ROOT].found) {
-                k = add_partition_root_rw(m->partitions + PARTITION_ROOT);
-                if (k < 0)
-                        r = k;
-        }
+        if (m->partitions[PARTITION_ROOT].found)
+                RET_GATHER(r, add_partition_root_rw(m->partitions + PARTITION_ROOT));
 
         return r;
 }