From 3da4ddffa49235219f3b82a40ebd05112d326637 Mon Sep 17 00:00:00 2001 From: Nathan Zimmer Date: Wed, 20 Mar 2013 15:06:55 +1100 Subject: [PATCH] timer_list-convert-timer-list-to-be-a-proper-seq_file-v3 v3: Corrected the case where max_cpus != nr_cpu_ids by exiting early. Signed-off-by: Nathan Zimmer Reported-by: Dave Jones Cc: John Stultz Cc: Thomas Gleixner Cc: Stephen Boyd Signed-off-by: Andrew Morton --- kernel/time/timer_list.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c index 8251f3f7ca9f..93f2e0f40b7a 100644 --- a/kernel/time/timer_list.c +++ b/kernel/time/timer_list.c @@ -276,8 +276,8 @@ static int timer_list_show(struct seq_file *m, void *v) /* * This itererator really needs some explanation since it is offset and has * two passes, one of which is controlled by a config option. - * In a hotplugged system some cpus, including cpu 0, may be missing so we have - * to use cpumask_* to iterate over the cpus. + * In a hotpluggable systems some cpus, including cpu 0 and the last cpu, may + * be missing so we have to use cpumask_* to iterate over the cpus. * For the first pass: * It returns 1 for the header position. * For cpu 0 it returns 2 and the final possible cpu would be nr_cpu_ids + 1. @@ -285,6 +285,8 @@ static int timer_list_show(struct seq_file *m, void *v) * It returnes nr_cpu_ids + 1 for the second header position. * For cpu 0 it returns nr_cpu_ids + 2 * The final possible cpu would be nr_cpu_ids + nr_cpu_ids + 2. + * It is also important to remember that cpumask_next returns >= nr_cpu_ids if + * no further cpus set. */ static void *timer_list_start(struct seq_file *file, loff_t *offset) { @@ -294,11 +296,9 @@ static void *timer_list_start(struct seq_file *file, loff_t *offset) return (void *) 1; if (n < nr_cpu_ids + 1) { - n--; - if (n > 0) - n = cpumask_next(n - 1, cpu_online_mask); - else - n = cpumask_first(cpu_online_mask); + n = cpumask_next(n - 2, cpu_online_mask); + if (n >= nr_cpu_ids) + n = nr_cpu_ids; *offset = n + 1; return (void *)(unsigned long)(n + 2); } @@ -309,10 +309,9 @@ static void *timer_list_start(struct seq_file *file, loff_t *offset) if (n < nr_cpu_ids * 2 + 2) { n -= (nr_cpu_ids + 2); - if (n > 0) - n = cpumask_next(n - 1, cpu_online_mask); - else - n = cpumask_first(cpu_online_mask); + n = cpumask_next(n - 1, cpu_online_mask); + if (n >= nr_cpu_ids) + return NULL; *offset = n + 2 + nr_cpu_ids; return (void *)(unsigned long)(n + 3 + nr_cpu_ids); } -- 2.39.5