Commit fd3d664f authored by Eric Dumazet's avatar Eric Dumazet Committed by Linus Torvalds

percpu_counter: fix CPU unplug race in percpu_counter_destroy()

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: default avatarEric Dumazet <dada1@cosmosbay.com>
Acked-by: default avatarDavid S. Miller <davem@davemloft.net>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Mingming Cao <cmm@us.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent fe102c71
...@@ -104,13 +104,13 @@ void percpu_counter_destroy(struct percpu_counter *fbc) ...@@ -104,13 +104,13 @@ void percpu_counter_destroy(struct percpu_counter *fbc)
if (!fbc->counters) if (!fbc->counters)
return; return;
free_percpu(fbc->counters);
fbc->counters = NULL;
#ifdef CONFIG_HOTPLUG_CPU #ifdef CONFIG_HOTPLUG_CPU
mutex_lock(&percpu_counters_lock); mutex_lock(&percpu_counters_lock);
list_del(&fbc->list); list_del(&fbc->list);
mutex_unlock(&percpu_counters_lock); mutex_unlock(&percpu_counters_lock);
#endif #endif
free_percpu(fbc->counters);
fbc->counters = NULL;
} }
EXPORT_SYMBOL(percpu_counter_destroy); EXPORT_SYMBOL(percpu_counter_destroy);
......
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