zonelist.c: Fix the coalescing of identical ranges
authorH. Peter Anvin <hpa@zytor.com>
Wed, 9 Apr 2008 17:49:51 +0000 (10:49 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Wed, 9 Apr 2008 17:49:51 +0000 (10:49 -0700)
The old code could fail to coalesce backwards in the case where a
range is totally obliterated.  For now, just scan the whole list.

com32/lib/syslinux/zonelist.c

index 44cec3f..62b1cf3 100644 (file)
@@ -76,7 +76,7 @@ int syslinux_add_memmap(struct syslinux_memmap **list,
 {
   addr_t last;
   struct syslinux_memmap *mp, **mpp;
-  struct syslinux_memmap *mpi, **mppi;
+  struct syslinux_memmap *mpi;
   struct syslinux_memmap *range;
   enum syslinux_memmap_types oldtype;
 
@@ -94,9 +94,6 @@ int syslinux_add_memmap(struct syslinux_memmap **list,
     mpp = &mp->next;
   }
 
-  /* Remember where we started messing with things. */
-  mppi = mpp;
-
   if (start < mp->start || mp->type == SMT_END) {
     range = malloc(sizeof(*range));
     if (!range)
@@ -129,9 +126,11 @@ int syslinux_add_memmap(struct syslinux_memmap **list,
   /* Now the map is correct, but quite possibly not optimal.  Scan the
      map for ranges which are redundant and remove them.  This is
      technically excessive, since we scan the list to the end even
-     though only part of it could have changed.  Eventually we might
-     care enough to save an end pointer from the operation above. */
-  mpi = *mppi;
+     though only part of it could have changed.  In particular, the first
+     entry that could change is one earlier than the first one changed
+     above, and once we stop changing things, there shouldn't be any
+     more changes. */
+  mpi = *list;
   while (mpi->type != SMT_END) {
     mp = mpi->next;
     if (mpi->type == mp->type) {