]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
x86 boot: proper use of ARRAY_SIZE instead of repeated E820MAX constant
authorPaul Jackson <pj@sgi.com>
Wed, 14 May 2008 15:15:34 +0000 (08:15 -0700)
committerThomas Gleixner <tglx@linutronix.de>
Sun, 25 May 2008 08:55:11 +0000 (10:55 +0200)
This patch is motivated by a subsequent patch which will allow for more
memory map entries on EFI supported systems than can be passed via the x86
legacy BIOS E820 interface.  The legacy interface is limited to E820MAX ==
128 memory entries, and that "E820MAX" manifest constant was used as the
size for several arrays and loops over those arrays.

The primary change in this patch is to change code loop sizes over those
arrays from using the constant E820MAX, to using the ARRAY_SIZE() macro
evaluated for the array being looped.  That way, a subsequent patch can
change the size of some of these arrays, without breaking this code.

This patch also adds a parameter to the sanitize_e820_map() routine,
which had an implicit size for the array passed it of E820MAX entries.
This new parameter explicitly passes the size of said array.  Once again,
this will allow a subsequent patch to change that array size for some
calls to sanitize_e820_map() without breaking the code.

As part of enhancing the sanitize_e820_map() interface this way, I further
combined the unnecessarily distinct x86_32 and x86_64 declarations for
this routine into a single, commonly used, declaration.

This patch in itself should make no difference to the resulting kernel
binary.

[ mingo@elte.hu: merged to -tip ]

Signed-off-by: Paul Jackson <pj@sgi.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
arch/x86/boot/memory.c
arch/x86/kernel/e820.c
arch/x86/kernel/e820_64.c
arch/x86/mach-default/setup.c
arch/x86/mach-voyager/setup.c
include/asm-x86/e820.h
include/asm-x86/setup.h

index acad32eb4290861b1539553c1e8eb49f7ec82e92..53165c97336b21406f49307cb4932c87468d32d9 100644 (file)
@@ -13,6 +13,7 @@
  */
 
 #include "boot.h"
+#include <linux/kernel.h>
 
 #define SMAP   0x534d4150      /* ASCII "SMAP" */
 
@@ -53,7 +54,7 @@ static int detect_memory_e820(void)
 
                count++;
                desc++;
-       } while (next && count < E820MAX);
+       } while (next && count < ARRAY_SIZE(boot_params.e820_map));
 
        return boot_params.e820_entries = count;
 }
index 2cb686f60d0dc9dce2431f91544c3ec94915172d..2396b9da8027cf1fd5f38ee047ec39986ca470c7 100644 (file)
@@ -95,7 +95,7 @@ void __init add_memory_region(u64 start, u64 size, int type)
 {
        int x = e820.nr_map;
 
-       if (x == E820MAX) {
+       if (x == ARRAY_SIZE(e820.map)) {
                printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
                return;
        }
@@ -142,7 +142,8 @@ void __init e820_print_map(char *who)
  * replaces the original e820 map with a new one, removing overlaps.
  *
  */
-int __init sanitize_e820_map(struct e820entry *biosmap, char *pnr_map)
+int __init sanitize_e820_map(struct e820entry *biosmap, int max_nr_map,
+                               char *pnr_map)
 {
        struct change_member {
                struct e820entry *pbios; /* pointer to original bios entry */
@@ -314,7 +315,7 @@ int __init sanitize_e820_map(struct e820entry *biosmap, char *pnr_map)
                                         * no more space left for new
                                         * bios entries ?
                                         */
-                                       if (++new_bios_entry >= E820MAX)
+                                       if (++new_bios_entry >= max_nr_map)
                                                break;
                        }
                        if (current_type != 0)  {
@@ -403,7 +404,7 @@ void __init update_e820(void)
        u8 nr_map;
 
        nr_map = e820.nr_map;
-       if (sanitize_e820_map(e820.map, &nr_map))
+       if (sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &nr_map))
                return;
        e820.nr_map = nr_map;
        printk(KERN_INFO "modified physical RAM map:\n");
index c10b4aece5e4a9d065ee5739d41cc8071e575641..58dc6eee4d4f3e6de2d8bab4a873a67f5b87dce4 100644 (file)
@@ -413,7 +413,9 @@ char *__init machine_specific_memory_setup(void)
         * Otherwise fake a memory map; one section from 0k->640k,
         * the next section from 1mb->appropriate_mem_k
         */
-       sanitize_e820_map(boot_params.e820_map, &boot_params.e820_entries);
+       sanitize_e820_map(boot_params.e820_map,
+                       ARRAY_SIZE(boot_params.e820_map),
+                       &boot_params.e820_entries);
        if (copy_e820_map(boot_params.e820_map, boot_params.e820_entries) < 0)
                early_panic("Cannot find a valid memory map");
        printk(KERN_INFO "BIOS-provided physical RAM map:\n");
@@ -484,7 +486,7 @@ void __init finish_e820_parsing(void)
        if (userdef) {
                char nr = e820.nr_map;
 
-               if (sanitize_e820_map(e820.map, &nr) < 0)
+               if (sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &nr) < 0)
                        early_panic("Invalid user supplied memory map");
                e820.nr_map = nr;
 
index 0c28a071824c2bd0789eb9c7d929615e8ba944d1..38a856c4fc07a891d5e5705789135e8431858d53 100644 (file)
@@ -163,7 +163,9 @@ char * __init machine_specific_memory_setup(void)
         * Otherwise fake a memory map; one section from 0k->640k,
         * the next section from 1mb->appropriate_mem_k
         */
-       sanitize_e820_map(boot_params.e820_map, &boot_params.e820_entries);
+       sanitize_e820_map(boot_params.e820_map,
+                       ARRAY_SIZE(boot_params.e820_map),
+                       &boot_params.e820_entries);
        if (copy_e820_map(boot_params.e820_map, boot_params.e820_entries)
            < 0) {
                unsigned long mem_size;
index 5ae5466b9eb9c3b9850fca6617e36dab2c653da7..662b5c0a77d691cee4dc8e9ddace03fe2499c956 100644 (file)
@@ -111,7 +111,9 @@ char *__init machine_specific_memory_setup(void)
         * Otherwise fake a memory map; one section from 0k->640k,
         * the next section from 1mb->appropriate_mem_k
         */
-       sanitize_e820_map(boot_params.e820_map, &boot_params.e820_entries);
+       sanitize_e820_map(boot_params.e820_map,
+                       ARRAY_SIZE(boot_params.e820_map),
+                       &boot_params.e820_entries);
        if (copy_e820_map(boot_params.e820_map, boot_params.e820_entries)
            < 0) {
                unsigned long mem_size;
index b5b519feba1ded324a95a3a522dc90e8db2a7f64..65c891d2a4cb4ff7a9c58ff14fa141f3ac23bd65 100644 (file)
@@ -27,7 +27,8 @@ extern int e820_any_mapped(u64 start, u64 end, unsigned type);
 extern int e820_all_mapped(u64 start, u64 end, unsigned type);
 extern void add_memory_region(u64 start, u64 size, int type);
 extern void e820_print_map(char *who);
-extern int sanitize_e820_map(struct e820entry *biosmap, char *pnr_map);
+extern int
+sanitize_e820_map(struct e820entry *biosmap, int max_nr_map, char *pnr_map);
 extern int copy_e820_map(struct e820entry *biosmap, int nr_map);
 extern u64 update_memory_range(u64 start, u64 size, unsigned old_type,
                               unsigned new_type);
index fa6763af8d2686c8d1b52a023f72c70806ec5bc4..ffa0f540fc7fe257ce1754edce819c139353ad41 100644 (file)
@@ -56,7 +56,6 @@ char * __init machine_specific_memory_setup(void);
 char *memory_setup(void);
 
 int __init copy_e820_map(struct e820entry *biosmap, int nr_map);
-int __init sanitize_e820_map(struct e820entry *biosmap, char *pnr_map);
 void __init add_memory_region(unsigned long long start,
                              unsigned long long size, int type);