Skip to content

Commit d52c056

Browse files
Sebastian Andrzej SiewiorIngo Molnar
authored andcommitted
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: 6b2c284 ("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>
1 parent 5bc653b commit d52c056

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

arch/x86/kernel/apic/x2apic_cluster.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static void init_x2apic_ldr(void)
155155
/*
156156
* At CPU state changes, update the x2apic cluster sibling info.
157157
*/
158-
int x2apic_prepare_cpu(unsigned int cpu)
158+
static int x2apic_prepare_cpu(unsigned int cpu)
159159
{
160160
if (!zalloc_cpumask_var(&per_cpu(cpus_in_cluster, cpu), GFP_KERNEL))
161161
return -ENOMEM;
@@ -168,7 +168,7 @@ int x2apic_prepare_cpu(unsigned int cpu)
168168
return 0;
169169
}
170170

171-
int x2apic_dead_cpu(unsigned int this_cpu)
171+
static int x2apic_dead_cpu(unsigned int this_cpu)
172172
{
173173
int cpu;
174174

@@ -186,13 +186,18 @@ int x2apic_dead_cpu(unsigned int this_cpu)
186186
static int x2apic_cluster_probe(void)
187187
{
188188
int cpu = smp_processor_id();
189+
int ret;
189190

190191
if (!x2apic_mode)
191192
return 0;
192193

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+
}
193200
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);
196201
return 1;
197202
}
198203

0 commit comments

Comments
 (0)