lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1485641531-22124-36-git-send-email-mingo@kernel.org>
Date:   Sat, 28 Jan 2017 23:11:56 +0100
From:   Ingo Molnar <mingo@...nel.org>
To:     linux-kernel@...r.kernel.org
Cc:     Andrew Morton <akpm@...ux-foundation.org>,
        Andy Lutomirski <luto@...capital.net>,
        Borislav Petkov <bp@...en8.de>,
        "H . Peter Anvin" <hpa@...or.com>,
        Linus Torvalds <torvalds@...ux-foundation.org>,
        Peter Zijlstra <peterz@...radead.org>,
        Thomas Gleixner <tglx@...utronix.de>,
        Yinghai Lu <yinghai@...nel.org>
Subject: [PATCH 35/50] x86/boot/e820: Simplify e820_reserve_resources()

Remove unnecessary duplications of "e820_table->entries[i]." via a local
variable, plus pass in 'entry' to the type_to_*() functions which further
improves the readability of the code - and other small tweaks.

No change in functionality.

Cc: Alex Thorlton <athorlton@....com>
Cc: Andy Lutomirski <luto@...nel.org>
Cc: Borislav Petkov <bp@...en8.de>
Cc: Brian Gerst <brgerst@...il.com>
Cc: Dan Williams <dan.j.williams@...el.com>
Cc: Denys Vlasenko <dvlasenk@...hat.com>
Cc: H. Peter Anvin <hpa@...or.com>
Cc: Huang, Ying <ying.huang@...el.com>
Cc: Josh Poimboeuf <jpoimboe@...hat.com>
Cc: Juergen Gross <jgross@...e.com>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Paul Jackson <pj@....com>
Cc: Peter Zijlstra <peterz@...radead.org>
Cc: Rafael J. Wysocki <rjw@...k.pl>
Cc: Tejun Heo <tj@...nel.org>
Cc: Thomas Gleixner <tglx@...utronix.de>
Cc: Wei Yang <richard.weiyang@...il.com>
Cc: Yinghai Lu <yinghai@...nel.org>
Cc: linux-kernel@...r.kernel.org
Signed-off-by: Ingo Molnar <mingo@...nel.org>
---
 arch/x86/kernel/e820.c | 36 +++++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index cdf224992c27..511402d88795 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -953,9 +953,9 @@ void __init e820__finish_early_params(void)
 	}
 }
 
-static const char *__init e820_type_to_string(int e820_type)
+static const char *__init e820_type_to_string(struct e820_entry *entry)
 {
-	switch (e820_type) {
+	switch (entry->type) {
 	case E820_RESERVED_KERN: /* Fall-through: */
 	case E820_RAM:		 return "System RAM";
 	case E820_ACPI:		 return "ACPI Tables";
@@ -967,9 +967,9 @@ static const char *__init e820_type_to_string(int e820_type)
 	}
 }
 
-static unsigned long __init e820_type_to_iomem_type(int e820_type)
+static unsigned long __init e820_type_to_iomem_type(struct e820_entry *entry)
 {
-	switch (e820_type) {
+	switch (entry->type) {
 	case E820_RESERVED_KERN: /* Fall-through: */
 	case E820_RAM:		 return IORESOURCE_SYSTEM_RAM;
 	case E820_ACPI:		 /* Fall-through: */
@@ -981,9 +981,9 @@ static unsigned long __init e820_type_to_iomem_type(int e820_type)
 	}
 }
 
-static unsigned long __init e820_type_to_iores_desc(int e820_type)
+static unsigned long __init e820_type_to_iores_desc(struct e820_entry *entry)
 {
-	switch (e820_type) {
+	switch (entry->type) {
 	case E820_ACPI:		 return IORES_DESC_ACPI_TABLES;
 	case E820_NVS:		 return IORES_DESC_ACPI_NV_STORAGE;
 	case E820_PMEM:		 return IORES_DESC_PERSISTENT_MEMORY;
@@ -1027,27 +1027,29 @@ void __init e820_reserve_resources(void)
 	struct resource *res;
 	u64 end;
 
-	res = alloc_bootmem(sizeof(struct resource) * e820_table->nr_entries);
+	res = alloc_bootmem(sizeof(*res) * e820_table->nr_entries);
 	e820_res = res;
+
 	for (i = 0; i < e820_table->nr_entries; i++) {
-		end = e820_table->entries[i].addr + e820_table->entries[i].size - 1;
+		struct e820_entry *entry = e820_table->entries + i;
+
+		end = entry->addr + entry->size - 1;
 		if (end != (resource_size_t)end) {
 			res++;
 			continue;
 		}
-		res->name = e820_type_to_string(e820_table->entries[i].type);
-		res->start = e820_table->entries[i].addr;
-		res->end = end;
-
-		res->flags = e820_type_to_iomem_type(e820_table->entries[i].type);
-		res->desc = e820_type_to_iores_desc(e820_table->entries[i].type);
+		res->start = entry->addr;
+		res->end   = end;
+		res->name  = e820_type_to_string(entry);
+		res->flags = e820_type_to_iomem_type(entry);
+		res->desc  = e820_type_to_iores_desc(entry);
 
 		/*
 		 * don't register the region that could be conflicted with
 		 * pci device BAR resource and insert them later in
 		 * pcibios_resource_survey()
 		 */
-		if (do_mark_busy(e820_table->entries[i].type, res)) {
+		if (do_mark_busy(entry->type, res)) {
 			res->flags |= IORESOURCE_BUSY;
 			insert_resource(&iomem_resource, res);
 		}
@@ -1055,9 +1057,9 @@ void __init e820_reserve_resources(void)
 	}
 
 	for (i = 0; i < e820_table_firmware->nr_entries; i++) {
-		struct e820_entry *entry = &e820_table_firmware->entries[i];
+		struct e820_entry *entry = e820_table_firmware->entries + i;
 
-		firmware_map_add_early(entry->addr, entry->addr + entry->size, e820_type_to_string(entry->type));
+		firmware_map_add_early(entry->addr, entry->addr + entry->size, e820_type_to_string(entry));
 	}
 }
 
-- 
2.7.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ