]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
efi: use CMP() more
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 18 Mar 2022 18:00:10 +0000 (19:00 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 18 Mar 2022 18:00:10 +0000 (19:00 +0100)
src/boot/efi/boot.c

index ae252845274c6774503ce22a61dacc695d04174d..9ed8daed42ecdbc1d3789032c349c9364d460636 100644 (file)
@@ -1655,10 +1655,9 @@ static INTN config_entry_compare(const ConfigEntry *a, const ConfigEntry *b) {
         assert(b);
 
         /* Order entries that have no tries left to the end of the list */
-        if (a->tries_left == 0 && b->tries_left != 0)
-                return 1;
-        if (a->tries_left != 0 && b->tries_left == 0)
-                return -1;
+        r = CMP(a->tries_left == 0, b->tries_left == 0);
+        if (r != 0)
+                return r;
 
         /* If there's a sort key defined for *both* entries, then we do new-style ordering, i.e. by
          * sort-key/machine-id/version, with a final fallback to id. If there's no sort key for either, we do
@@ -1667,8 +1666,8 @@ static INTN config_entry_compare(const ConfigEntry *a, const ConfigEntry *b) {
         r = CMP(!a->sort_key, !b->sort_key);
         if (r != 0) /* one is old-style, one new-style */
                 return r;
-        if (a->sort_key && b->sort_key) {
 
+        if (a->sort_key && b->sort_key) {
                 r = strcmp(a->sort_key, b->sort_key);
                 if (r != 0)
                         return r;
@@ -1691,23 +1690,16 @@ static INTN config_entry_compare(const ConfigEntry *a, const ConfigEntry *b) {
         if (r != 0)
                 return r;
 
-        if (a->tries_left == UINTN_MAX ||
-            b->tries_left == UINTN_MAX)
+        if (a->tries_left == UINTN_MAX || b->tries_left == UINTN_MAX)
                 return 0;
 
         /* If both items have boot counting, and otherwise are identical, put the entry with more tries left first */
-        if (a->tries_left < b->tries_left)
-                return 1;
-        if (a->tries_left > b->tries_left)
-                return -1;
+        r = -CMP(a->tries_left, b->tries_left);
+        if (r != 0)
+                return r;
 
         /* If they have the same number of tries left, then let the one win which was tried fewer times so far */
-        if (a->tries_done > b->tries_done)
-                return 1;
-        if (a->tries_done < b->tries_done)
-                return -1;
-
-        return 0;
+        return CMP(a->tries_done, b->tries_done);
 }
 
 static UINTN config_entry_find(Config *config, const CHAR16 *needle) {