bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] acpi: handle return value of mmap consistently in acpi.c


From: Andrea Monaco
Subject: [PATCH] acpi: handle return value of mmap consistently in acpi.c
Date: Fri, 19 Nov 2021 00:05:38 +0100

Hello.


In the first chunk, munmap is not needed, because mmap_phys_acpi_header
only returns non-zero when mmap fails.
In the second, a possible error condition was previously ignored.
In the last chunk, I moved a common identical branch lower.


Bye,

Andrea Monaco



diff --git a/acpi/acpi.c b/acpi/acpi.c
index acbf79c7..7ab139f6 100644
--- a/acpi/acpi.c
+++ b/acpi/acpi.c
@@ -114,7 +114,6 @@ acpi_get_num_tables(size_t *num_tables)
 
   err = mmap_phys_acpi_header(sdt_base, &root_sdt, &virt_addr, fd_mem);
   if (err) {
-    munmap(virt_addr, ESCD_SIZE);
     return err;
   }
 
@@ -139,6 +138,11 @@ acpi_get_num_tables(size_t *num_tables)
         err = mmap_phys_acpi_header(acpi_ptr32, &next, &virt_addr2, fd_mem);
       }
 
+      if (err) {
+       munmap(virt_addr, ESCD_SIZE);
+       return err;
+      }
+
       if (next->signature[0] == '\0' || next->length == 0) {
         munmap(virt_addr2, ESCD_SIZE);
         continue;
@@ -223,7 +227,6 @@ acpi_get_tables(struct acpi_table **tables)
 
   err = mmap_phys_acpi_header(sdt_base, &root_sdt, &virt_addr, fd_mem);
   if (err) {
-    munmap(virt_addr, ESCD_SIZE);
     return err;
   }
 
@@ -243,16 +246,13 @@ acpi_get_tables(struct acpi_table **tables)
       uintptr_t acpi_ptr64 = (uintptr_t)*((uint64_t *)(acpi_ptr + i*sz_ptr));
       if (is_64bit) {
         err = mmap_phys_acpi_header(acpi_ptr64, &next, &virt_addr2, fd_mem);
-        if (err) {
-          munmap(virt_addr, ESCD_SIZE);
-          return err;
-        }
       } else {
         err = mmap_phys_acpi_header(acpi_ptr32, &next, &virt_addr2, fd_mem);
-        if (err) {
-          munmap(virt_addr, ESCD_SIZE);
-          return err;
-        }
+      }
+
+      if (err) {
+       munmap(virt_addr, ESCD_SIZE);
+       return err;
       }
 
       if (next->signature[0] == '\0' || next->length == 0) {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]