Commit c8ed0010 authored by Rusty Russell's avatar Rusty Russell

Fix weird uses of num_online_cpus().

This may be OK in archs with contiguous CPU numbers and without
hotplug CPUs, but it sets a terrible example.

And open-coding it like drivers/scsi/hpsa.c is just weird.

BTRFS has a weird comparison with num_online_cpus() too, but since
BTRFS just screwed up my test machines' root partition, I'm not
touching it :)
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
Reported-by: default avatarOleg Drokin <green@linuxhacker.ru>
parent 2f0f267e
...@@ -376,7 +376,7 @@ void __init smp_cpus_done(unsigned int max_cpus) ...@@ -376,7 +376,7 @@ void __init smp_cpus_done(unsigned int max_cpus)
if (!cpumask_equal(&cpu_callin_map, cpu_online_mask)) if (!cpumask_equal(&cpu_callin_map, cpu_online_mask))
BUG(); BUG();
for (cpu_id = 0 ; cpu_id < num_online_cpus() ; cpu_id++) for_each_online_cpu(cpu_id)
show_cpu_info(cpu_id); show_cpu_info(cpu_id);
/* /*
......
...@@ -99,7 +99,7 @@ static inline int init_new_context(struct task_struct *tsk, ...@@ -99,7 +99,7 @@ static inline int init_new_context(struct task_struct *tsk,
{ {
int i; int i;
for (i = 0; i < num_online_cpus(); i++) for_each_online_cpu(i)
cpu_context(i, mm) = NO_CONTEXT; cpu_context(i, mm) = NO_CONTEXT;
return 0; return 0;
......
...@@ -363,7 +363,7 @@ void flush_tlb_mm(struct mm_struct *mm) ...@@ -363,7 +363,7 @@ void flush_tlb_mm(struct mm_struct *mm)
smp_call_function(flush_tlb_mm_ipi, (void *)mm, 1); smp_call_function(flush_tlb_mm_ipi, (void *)mm, 1);
} else { } else {
int i; int i;
for (i = 0; i < num_online_cpus(); i++) for_each_online_cpu(i)
if (smp_processor_id() != i) if (smp_processor_id() != i)
cpu_context(i, mm) = 0; cpu_context(i, mm) = 0;
} }
...@@ -400,7 +400,7 @@ void flush_tlb_range(struct vm_area_struct *vma, ...@@ -400,7 +400,7 @@ void flush_tlb_range(struct vm_area_struct *vma,
smp_call_function(flush_tlb_range_ipi, (void *)&fd, 1); smp_call_function(flush_tlb_range_ipi, (void *)&fd, 1);
} else { } else {
int i; int i;
for (i = 0; i < num_online_cpus(); i++) for_each_online_cpu(i)
if (smp_processor_id() != i) if (smp_processor_id() != i)
cpu_context(i, mm) = 0; cpu_context(i, mm) = 0;
} }
...@@ -443,7 +443,7 @@ void flush_tlb_page(struct vm_area_struct *vma, unsigned long page) ...@@ -443,7 +443,7 @@ void flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
smp_call_function(flush_tlb_page_ipi, (void *)&fd, 1); smp_call_function(flush_tlb_page_ipi, (void *)&fd, 1);
} else { } else {
int i; int i;
for (i = 0; i < num_online_cpus(); i++) for_each_online_cpu(i)
if (smp_processor_id() != i) if (smp_processor_id() != i)
cpu_context(i, vma->vm_mm) = 0; cpu_context(i, vma->vm_mm) = 0;
} }
......
...@@ -45,7 +45,7 @@ void smp_send_stop(void) ...@@ -45,7 +45,7 @@ void smp_send_stop(void)
int i; int i;
printk(KERN_INFO "Stopping all CPUs..."); printk(KERN_INFO "Stopping all CPUs...");
for (i = 0; i < num_online_cpus(); i++) { for_each_online_cpu(i) {
if (i == current_thread->cpu) if (i == current_thread->cpu)
continue; continue;
os_write_file(cpu_data[i].ipi_pipe[1], "S", 1); os_write_file(cpu_data[i].ipi_pipe[1], "S", 1);
......
...@@ -6632,14 +6632,12 @@ static void fail_all_outstanding_cmds(struct ctlr_info *h) ...@@ -6632,14 +6632,12 @@ static void fail_all_outstanding_cmds(struct ctlr_info *h)
static void set_lockup_detected_for_all_cpus(struct ctlr_info *h, u32 value) static void set_lockup_detected_for_all_cpus(struct ctlr_info *h, u32 value)
{ {
int i, cpu; int cpu;
cpu = cpumask_first(cpu_online_mask); for_each_online_cpu(cpu) {
for (i = 0; i < num_online_cpus(); i++) {
u32 *lockup_detected; u32 *lockup_detected;
lockup_detected = per_cpu_ptr(h->lockup_detected, cpu); lockup_detected = per_cpu_ptr(h->lockup_detected, cpu);
*lockup_detected = value; *lockup_detected = value;
cpu = cpumask_next(cpu, cpu_online_mask);
} }
wmb(); /* be sure the per-cpu variables are out to memory */ wmb(); /* be sure the per-cpu variables are out to memory */
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment