diff options
author | Tang Chen <tangchen@cn.fujitsu.com> | 2012-09-25 09:12:30 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2012-10-05 07:54:46 -0400 |
commit | 5f7865f3e44db4c73fdc454fb2af40806212a7ca (patch) | |
tree | 279a1f2588b875019c80e2ae779bd66bb6544137 /kernel/sched | |
parent | 2b17c545a4cdbbbadcd7f1e9684c2d7db8f085a6 (diff) |
sched: Ensure 'sched_domains_numa_levels' is safe to use in other functions
We should temporarily reset 'sched_domains_numa_levels' to 0 after
it is reset to 'level' in sched_init_numa(). If it fails to allocate
memory for array sched_domains_numa_masks[][], the array will contain
less then 'level' members. This could be dangerous when we use it to
iterate array sched_domains_numa_masks[][] in other functions.
This patch set sched_domains_numa_levels to 0 before initializing
array sched_domains_numa_masks[][], and reset it to 'level' when
sched_domains_numa_masks[][] is fully initialized.
Signed-off-by: Tang Chen <tangchen@cn.fujitsu.com>
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1348578751-16904-2-git-send-email-tangchen@cn.fujitsu.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel/sched')
-rw-r--r-- | kernel/sched/core.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/kernel/sched/core.c b/kernel/sched/core.c index c17747236438..f895fdd32c5b 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c | |||
@@ -6122,6 +6122,17 @@ static void sched_init_numa(void) | |||
6122 | * numbers. | 6122 | * numbers. |
6123 | */ | 6123 | */ |
6124 | 6124 | ||
6125 | /* | ||
6126 | * Here, we should temporarily reset sched_domains_numa_levels to 0. | ||
6127 | * If it fails to allocate memory for array sched_domains_numa_masks[][], | ||
6128 | * the array will contain less then 'level' members. This could be | ||
6129 | * dangerous when we use it to iterate array sched_domains_numa_masks[][] | ||
6130 | * in other functions. | ||
6131 | * | ||
6132 | * We reset it to 'level' at the end of this function. | ||
6133 | */ | ||
6134 | sched_domains_numa_levels = 0; | ||
6135 | |||
6125 | sched_domains_numa_masks = kzalloc(sizeof(void *) * level, GFP_KERNEL); | 6136 | sched_domains_numa_masks = kzalloc(sizeof(void *) * level, GFP_KERNEL); |
6126 | if (!sched_domains_numa_masks) | 6137 | if (!sched_domains_numa_masks) |
6127 | return; | 6138 | return; |
@@ -6176,6 +6187,8 @@ static void sched_init_numa(void) | |||
6176 | } | 6187 | } |
6177 | 6188 | ||
6178 | sched_domain_topology = tl; | 6189 | sched_domain_topology = tl; |
6190 | |||
6191 | sched_domains_numa_levels = level; | ||
6179 | } | 6192 | } |
6180 | #else | 6193 | #else |
6181 | static inline void sched_init_numa(void) | 6194 | static inline void sched_init_numa(void) |