[PATCH 1/1] x86_64: x86_64_cleanup_pda() should use nr_cpu_ids instead of NR_CPUS

From: Mike Travis
Date: Mon Feb 25 2008 - 13:33:48 EST


We allocate an array of nr_cpu_ids pointers, so we should respect its bonds.

Delay change of _cpu_pda after array initialization.

Also take into account that alloc_bootmem_low() :
- calls panic() if not enough memory
- already clears allocated memory

Signed-off-by: Eric Dumazet <dada1@xxxxxxxxxxxxx>
Signed-off-by: Mike Travis <travis@xxxxxxx>

---
arch/x86/kernel/head64.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)

--- a/arch/x86/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
@@ -151,18 +151,16 @@ void __init x86_64_start_kernel(char * r
void __init x86_64_cleanup_pda(void)
{
int i;
+ struct x8664_pda **new_cpu_pda;

- _cpu_pda = alloc_bootmem_low(nr_cpu_ids * sizeof(void *));
+ new_cpu_pda = alloc_bootmem_low(nr_cpu_ids * sizeof(void *));

- if (!_cpu_pda)
- panic("Cannot allocate cpu pda table\n");

+ for (i = 0; i < nr_cpu_ids; i++)
+ if (_cpu_pda_init[i] != &boot_cpu_pda[i])
+ new_cpu_pda[i] = _cpu_pda_init[i];
+ mb();
+ _cpu_pda = new_cpu_pda;
/* cpu_pda() now points to allocated cpu_pda_table */
-
- for (i = 0; i < NR_CPUS; i++)
- if (_cpu_pda_init[i] == &boot_cpu_pda[i])
- cpu_pda(i) = NULL;
- else
- cpu_pda(i) = _cpu_pda_init[i];
}
#endif

--
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/