]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Inline some inerator variables
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 11 Jun 2021 10:23:46 +0000 (12:23 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 15 Jun 2021 20:01:42 +0000 (22:01 +0200)
src/boot/bootctl.c
src/shared/efi-loader.c

index 361209a1bcda1f6a9378c46d096a41e4290efb25..7d12b5af7cdff048575f0f3ff62adefd54cc3701 100644 (file)
@@ -288,7 +288,7 @@ static int print_efi_option(uint16_t id, bool in_order) {
 
 static int status_variables(void) {
         _cleanup_free_ uint16_t *options = NULL, *order = NULL;
-        int n_options, n_order, i;
+        int n_options, n_order;
 
         n_options = efi_get_boot_options(&options);
         if (n_options == -ENOENT)
@@ -306,14 +306,12 @@ static int status_variables(void) {
 
         /* print entries in BootOrder first */
         printf("Boot Loaders Listed in EFI Variables:\n");
-        for (i = 0; i < n_order; i++)
+        for (int i = 0; i < n_order; i++)
                 print_efi_option(order[i], true);
 
         /* print remaining entries */
-        for (i = 0; i < n_options; i++) {
-                int j;
-
-                for (j = 0; j < n_order; j++)
+        for (int i = 0; i < n_options; i++) {
+                for (int j = 0; j < n_order; j++)
                         if (options[i] == order[j])
                                 goto next_option;
 
@@ -726,7 +724,7 @@ static int find_slot(sd_id128_t uuid, const char *path, uint16_t *id) {
 static int insert_into_order(uint16_t slot, bool first) {
         _cleanup_free_ uint16_t *order = NULL;
         uint16_t *t;
-        int n, i;
+        int n;
 
         n = efi_get_boot_order(&order);
         if (n <= 0)
@@ -738,7 +736,7 @@ static int insert_into_order(uint16_t slot, bool first) {
                 return 0;
 
         /* are we already in the boot order? */
-        for (i = 0; i < n; i++) {
+        for (int i = 0; i < n; i++) {
                 if (order[i] != slot)
                         continue;
 
@@ -770,13 +768,13 @@ static int insert_into_order(uint16_t slot, bool first) {
 
 static int remove_from_order(uint16_t slot) {
         _cleanup_free_ uint16_t *order = NULL;
-        int n, i;
+        int n;
 
         n = efi_get_boot_order(&order);
         if (n <= 0)
                 return n;
 
-        for (i = 0; i < n; i++) {
+        for (int i = 0; i < n; i++) {
                 if (order[i] != slot)
                         continue;
 
@@ -1295,7 +1293,6 @@ static int verb_status(int argc, char *argv[], void *userdata) {
                 _cleanup_free_ char *fw_type = NULL, *fw_info = NULL, *loader = NULL, *loader_path = NULL, *stub = NULL;
                 sd_id128_t loader_part_uuid = SD_ID128_NULL;
                 uint64_t loader_features = 0;
-                size_t i;
                 int have;
 
                 read_efi_var(EFI_LOADER_VARIABLE(LoaderFirmwareType), &fw_type);
@@ -1334,7 +1331,7 @@ static int verb_status(int argc, char *argv[], void *userdata) {
                 printf("Current Boot Loader:\n");
                 printf("      Product: %s%s%s\n", ansi_highlight(), strna(loader), ansi_normal());
 
-                for (i = 0; i < ELEMENTSOF(flags); i++)
+                for (size_t i = 0; i < ELEMENTSOF(flags); i++)
                         print_yes_no_line(i == 0, FLAGS_SET(loader_features, flags[i].flag), flags[i].name);
 
                 sd_id128_t bootloader_esp_uuid;
@@ -1432,13 +1429,11 @@ static int verb_list(int argc, char *argv[], void *userdata) {
         if (config.n_entries == 0)
                 log_info("No boot loader entries found.");
         else {
-                size_t n;
-
                 (void) pager_open(arg_pager_flags);
 
                 printf("Boot Loader Entries:\n");
 
-                for (n = 0; n < config.n_entries; n++) {
+                for (size_t n = 0; n < config.n_entries; n++) {
                         r = boot_entry_show(config.entries + n, n == (size_t) config.default_entry);
                         if (r < 0)
                                 return r;
index 55f85e695f56872d199a259750422ab146a67a7f..f5076fc02c7a84ea5bee6f8664c9d74b4ba9ae0f 100644 (file)
@@ -345,9 +345,7 @@ static void id128_to_efi_guid(sd_id128_t id, void *guid) {
 }
 
 static uint16_t *tilt_slashes(uint16_t *s) {
-        uint16_t *p;
-
-        for (p = s; *p; p++)
+        for (uint16_t *p = s; *p; p++)
                 if (*p == '/')
                         *p = '\\';
 
@@ -465,11 +463,11 @@ int efi_set_boot_order(uint16_t *order, size_t n) {
 }
 
 static int boot_id_hex(const char s[static 4]) {
-        int id = 0, i;
+        int id = 0;
 
         assert(s);
 
-        for (i = 0; i < 4; i++)
+        for (int i = 0; i < 4; i++)
                 if (s[i] >= '0' && s[i] <= '9')
                         id |= (s[i] - '0') << (3 - i) * 4;
                 else if (s[i] >= 'A' && s[i] <= 'F')
@@ -595,12 +593,9 @@ int efi_loader_get_device_part_uuid(sd_id128_t *u) {
                    &parsed[12], &parsed[13], &parsed[14], &parsed[15]) != 16)
                 return -EIO;
 
-        if (u) {
-                unsigned i;
-
-                for (i = 0; i < ELEMENTSOF(parsed); i++)
+        if (u)
+                for (unsigned i = 0; i < ELEMENTSOF(parsed); i++)
                         u->bytes[i] = parsed[i];
-        }
 
         return 0;
 }
@@ -608,7 +603,7 @@ int efi_loader_get_device_part_uuid(sd_id128_t *u) {
 int efi_loader_get_entries(char ***ret) {
         _cleanup_free_ char16_t *entries = NULL;
         _cleanup_strv_free_ char **l = NULL;
-        size_t size, i, start;
+        size_t size;
         int r;
 
         assert(ret);
@@ -622,7 +617,7 @@ int efi_loader_get_entries(char ***ret) {
 
         /* The variable contains a series of individually NUL terminated UTF-16 strings. */
 
-        for (i = 0, start = 0;; i++) {
+        for (size_t i = 0, start = 0;; i++) {
                 _cleanup_free_ char *decoded = NULL;
                 bool end;
 
@@ -795,7 +790,6 @@ bool efi_has_tpm2(void) {
 #endif
 
 bool efi_loader_entry_name_valid(const char *s) {
-
         if (!filename_is_valid(s)) /* Make sure entry names fit in filenames */
                 return false;
 
@@ -803,9 +797,7 @@ bool efi_loader_entry_name_valid(const char *s) {
 }
 
 char *efi_tilt_backslashes(char *s) {
-        char *p;
-
-        for (p = s; *p; p++)
+        for (char *p = s; *p; p++)
                 if (*p == '\\')
                         *p = '/';