]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
* grub-core/disk/efi/efidisk.c: Transform iterate_child_devices into
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Fri, 1 Mar 2013 09:37:11 +0000 (10:37 +0100)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Fri, 1 Mar 2013 09:37:11 +0000 (10:37 +0100)
a FOR_CHILDREN macro.

ChangeLog
grub-core/disk/efi/efidisk.c

index 986871ce4eaa7e893907322c41cfdf50cc3f4544..ccd6c0a5e614f9d17b9f043612436af0863f1d22 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2013-03-01  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       * grub-core/disk/efi/efidisk.c: Transform iterate_child_devices into
+       a FOR_CHILDREN macro.
+
 2013-03-01  Vladimir Serbinenko  <phcoder@gmail.com>
 
        * grub-core/kern/main.c (grub_set_prefix_and_root): Strip trailing
index 19c59238452cb0a9b72ffb717a47727955a6962c..c883b2c756c0124fa14a05c63f4ee0c135ef2912 100644 (file)
@@ -175,39 +175,29 @@ find_parent_device (struct grub_efidisk_data *devices,
 }
 
 static int
-iterate_child_devices (struct grub_efidisk_data *devices,
-                      struct grub_efidisk_data *d,
-                      int (*hook) (struct grub_efidisk_data *child))
+is_child (struct grub_efidisk_data *child,
+         struct grub_efidisk_data *parent)
 {
-  struct grub_efidisk_data *p;
-
-  for (p = devices; p; p = p->next)
-    {
-      grub_efi_device_path_t *dp, *ldp;
-
-      dp = duplicate_device_path (p->device_path);
-      if (! dp)
-       return 0;
-
-      ldp = find_last_device_path (dp);
-      ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE;
-      ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE;
-      ldp->length[0] = sizeof (*ldp);
-      ldp->length[1] = 0;
+  grub_efi_device_path_t *dp, *ldp;
+  int ret;
 
-      if (grub_efi_compare_device_paths (dp, d->device_path) == 0)
-       if (hook (p))
-         {
-           grub_free (dp);
-           return 1;
-         }
+  dp = duplicate_device_path (child->device_path);
+  if (! dp)
+    return 0;
 
-      grub_free (dp);
-    }
+  ldp = find_last_device_path (dp);
+  ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE;
+  ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE;
+  ldp->length[0] = sizeof (*ldp);
+  ldp->length[1] = 0;
 
-  return 0;
+  ret = (grub_efi_compare_device_paths (dp, parent->device_path) == 0);
+  grub_free (dp);
+  return ret;
 }
 
+#define FOR_CHILDREN(p, dev) for (p = dev; p; p = p->next) if (is_child (p, d))
+
 /* Add a device into a list of devices in an ascending order.  */
 static void
 add_device (struct grub_efidisk_data **devices, struct grub_efidisk_data *d)
@@ -655,9 +645,10 @@ grub_efidisk_get_device_handle (grub_disk_t disk)
       {
        struct grub_efidisk_data *devices;
        grub_efi_handle_t handle = 0;
-       auto int find_partition (struct grub_efidisk_data *c);
+       struct grub_efidisk_data *c;
 
-       int find_partition (struct grub_efidisk_data *c)
+       devices = make_devices ();
+       FOR_CHILDREN (c, devices)
          {
            grub_efi_hard_drive_device_path_t hd;
 
@@ -673,14 +664,10 @@ grub_efidisk_get_device_handle (grub_disk_t disk)
                    == hd.partition_size))
              {
                handle = c->handle;
-               return 1;
+               break;
              }
-
-           return 0;
          }
 
-       devices = make_devices ();
-       iterate_child_devices (devices, d, find_partition);
        free_devices (devices);
 
        if (handle != 0)