]> xenbits.xensource.com Git - osstest/seabios.git/commitdiff
biostables: copy_fseg_table() function
authorEduardo Habkost <ehabkost@redhat.com>
Thu, 10 Dec 2020 15:26:43 +0000 (10:26 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Sat, 18 Dec 2021 16:39:12 +0000 (11:39 -0500)
Replace the common malloc_fseg() + memcpy() code pattern
with a helper function.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
src/fw/biostables.c

index 794b5be8334f36d2033355ab64b77e092ed3336c..a6f316fa39126de51b6179227c37dd30e59e7c24 100644 (file)
 
 struct pir_header *PirAddr VARFSEG;
 
+static void *
+copy_fseg_table(const char *name, void *pos, u32 size)
+{
+    void *newpos = malloc_fseg(size);
+    if (!newpos) {
+        warn_noalloc();
+        return NULL;
+    }
+    dprintf(1, "Copying %s from %p to %p\n", name, pos, newpos);
+    memcpy(newpos, pos, size);
+    return newpos;
+}
+
 void
 copy_pir(void *pos)
 {
@@ -33,14 +46,7 @@ copy_pir(void *pos)
         return;
     if (checksum(pos, p->size) != 0)
         return;
-    void *newpos = malloc_fseg(p->size);
-    if (!newpos) {
-        warn_noalloc();
-        return;
-    }
-    dprintf(1, "Copying PIR from %p to %p\n", pos, newpos);
-    memcpy(newpos, pos, p->size);
-    PirAddr = newpos;
+    PirAddr = copy_fseg_table("PIR", pos, p->size);
 }
 
 void
@@ -111,14 +117,7 @@ copy_acpi_rsdp(void *pos)
     int length = get_acpi_rsdp_length(pos, -1);
     if (length < 0)
         return;
-    void *newpos = malloc_fseg(length);
-    if (!newpos) {
-        warn_noalloc();
-        return;
-    }
-    dprintf(1, "Copying ACPI RSDP from %p to %p\n", pos, newpos);
-    memcpy(newpos, pos, length);
-    RsdpAddr = newpos;
+    RsdpAddr = copy_fseg_table("ACPI RSDP", pos, length);
 }
 
 void *find_acpi_rsdp(void)
@@ -305,14 +304,7 @@ copy_smbios(void *pos)
         return;
     if (checksum(pos+0x10, p->length-0x10) != 0)
         return;
-    struct smbios_entry_point *newpos = malloc_fseg(p->length);
-    if (!newpos) {
-        warn_noalloc();
-        return;
-    }
-    dprintf(1, "Copying SMBIOS entry point from %p to %p\n", pos, newpos);
-    memcpy(newpos, pos, p->length);
-    SMBiosAddr = newpos;
+    SMBiosAddr = copy_fseg_table("SMBIOS", pos, p->length);
 }
 
 void