diff options
author | Sebastian Andrzej Siewior <bigeasy@linutronix.de> | 2016-08-11 10:08:35 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2016-08-11 10:35:50 -0400 |
commit | d52c0569bab4edc888832df44dc7ac28517134f6 (patch) | |
tree | 08f85c178412248d9b491375c57ad9813f4e3e90 | |
parent | 5bc653b7318217c54244a14f248f1f07abe0a865 (diff) |
x86/apic/x2apic, smp/hotplug: Don't use before alloc in x2apic_cluster_probe()
I made a mistake while converting the driver to the hotplug state
machine and as a result x2apic_cluster_probe() was accessing
cpus_in_cluster before allocating it.
This patch fixes it by setting the cpumask after the allocation the
memory succeeded.
While at it, I marked two functions static which are only used within
this file.
Reported-by: Laura Abbott <labbott@redhat.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Fixes: 6b2c28471de5 ("x86/x2apic: Convert to CPU hotplug state machine")
Link: http://lkml.kernel.org/r/1470924515-9444-1-git-send-email-bigeasy@linutronix.de
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r-- | arch/x86/kernel/apic/x2apic_cluster.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c index 6368fa69d2af..54f35d988025 100644 --- a/arch/x86/kernel/apic/x2apic_cluster.c +++ b/arch/x86/kernel/apic/x2apic_cluster.c | |||
@@ -155,7 +155,7 @@ static void init_x2apic_ldr(void) | |||
155 | /* | 155 | /* |
156 | * At CPU state changes, update the x2apic cluster sibling info. | 156 | * At CPU state changes, update the x2apic cluster sibling info. |
157 | */ | 157 | */ |
158 | int x2apic_prepare_cpu(unsigned int cpu) | 158 | static int x2apic_prepare_cpu(unsigned int cpu) |
159 | { | 159 | { |
160 | if (!zalloc_cpumask_var(&per_cpu(cpus_in_cluster, cpu), GFP_KERNEL)) | 160 | if (!zalloc_cpumask_var(&per_cpu(cpus_in_cluster, cpu), GFP_KERNEL)) |
161 | return -ENOMEM; | 161 | return -ENOMEM; |
@@ -168,7 +168,7 @@ int x2apic_prepare_cpu(unsigned int cpu) | |||
168 | return 0; | 168 | return 0; |
169 | } | 169 | } |
170 | 170 | ||
171 | int x2apic_dead_cpu(unsigned int this_cpu) | 171 | static int x2apic_dead_cpu(unsigned int this_cpu) |
172 | { | 172 | { |
173 | int cpu; | 173 | int cpu; |
174 | 174 | ||
@@ -186,13 +186,18 @@ int x2apic_dead_cpu(unsigned int this_cpu) | |||
186 | static int x2apic_cluster_probe(void) | 186 | static int x2apic_cluster_probe(void) |
187 | { | 187 | { |
188 | int cpu = smp_processor_id(); | 188 | int cpu = smp_processor_id(); |
189 | int ret; | ||
189 | 190 | ||
190 | if (!x2apic_mode) | 191 | if (!x2apic_mode) |
191 | return 0; | 192 | return 0; |
192 | 193 | ||
194 | ret = cpuhp_setup_state(CPUHP_X2APIC_PREPARE, "X2APIC_PREPARE", | ||
195 | x2apic_prepare_cpu, x2apic_dead_cpu); | ||
196 | if (ret < 0) { | ||
197 | pr_err("Failed to register X2APIC_PREPARE\n"); | ||
198 | return 0; | ||
199 | } | ||
193 | cpumask_set_cpu(cpu, per_cpu(cpus_in_cluster, cpu)); | 200 | cpumask_set_cpu(cpu, per_cpu(cpus_in_cluster, cpu)); |
194 | cpuhp_setup_state(CPUHP_X2APIC_PREPARE, "X2APIC_PREPARE", | ||
195 | x2apic_prepare_cpu, x2apic_dead_cpu); | ||
196 | return 1; | 201 | return 1; |
197 | } | 202 | } |
198 | 203 | ||