Skip to content

Commit

Permalink
percpu_counter: fix CPU unplug race in percpu_counter_destroy()
Browse files Browse the repository at this point in the history
We should first delete the counter from percpu_counters list
before freeing memory, or a percpu_counter_hotcpu_callback()
could dereference a NULL pointer.

Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Acked-by: David S. Miller <davem@davemloft.net>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Mingming Cao <cmm@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Eric Dumazet authored and Linus Torvalds committed Dec 10, 2008
1 parent fe102c7 commit fd3d664
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/percpu_counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ void percpu_counter_destroy(struct percpu_counter *fbc)
if (!fbc->counters)
return;

free_percpu(fbc->counters);
fbc->counters = NULL;
#ifdef CONFIG_HOTPLUG_CPU
mutex_lock(&percpu_counters_lock);
list_del(&fbc->list);
mutex_unlock(&percpu_counters_lock);
#endif
free_percpu(fbc->counters);
fbc->counters = NULL;
}
EXPORT_SYMBOL(percpu_counter_destroy);

Expand Down

0 comments on commit fd3d664

Please sign in to comment.