From 523487f713bcc24302623a2326bc10ff4d5f03d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 18 Mar 2022 19:00:10 +0100 Subject: [PATCH] efi: use CMP() more --- src/boot/efi/boot.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c index ae252845274..9ed8daed42e 100644 --- a/src/boot/efi/boot.c +++ b/src/boot/efi/boot.c @@ -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) {