aboutsummaryrefslogtreecommitdiffstats
path: root/lib/percpu_counter.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/percpu_counter.c')
-rw-r--r--lib/percpu_counter.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/percpu_counter.c b/lib/percpu_counter.c
index 3b0ed80c1efd..3a59d84b2d1e 100644
--- a/lib/percpu_counter.c
+++ b/lib/percpu_counter.c
@@ -68,21 +68,27 @@ s64 __percpu_counter_sum(struct percpu_counter *fbc)
68} 68}
69EXPORT_SYMBOL(__percpu_counter_sum); 69EXPORT_SYMBOL(__percpu_counter_sum);
70 70
71void percpu_counter_init(struct percpu_counter *fbc, s64 amount) 71int percpu_counter_init(struct percpu_counter *fbc, s64 amount)
72{ 72{
73 spin_lock_init(&fbc->lock); 73 spin_lock_init(&fbc->lock);
74 fbc->count = amount; 74 fbc->count = amount;
75 fbc->counters = alloc_percpu(s32); 75 fbc->counters = alloc_percpu(s32);
76 if (!fbc->counters)
77 return -ENOMEM;
76#ifdef CONFIG_HOTPLUG_CPU 78#ifdef CONFIG_HOTPLUG_CPU
77 mutex_lock(&percpu_counters_lock); 79 mutex_lock(&percpu_counters_lock);
78 list_add(&fbc->list, &percpu_counters); 80 list_add(&fbc->list, &percpu_counters);
79 mutex_unlock(&percpu_counters_lock); 81 mutex_unlock(&percpu_counters_lock);
80#endif 82#endif
83 return 0;
81} 84}
82EXPORT_SYMBOL(percpu_counter_init); 85EXPORT_SYMBOL(percpu_counter_init);
83 86
84void percpu_counter_destroy(struct percpu_counter *fbc) 87void percpu_counter_destroy(struct percpu_counter *fbc)
85{ 88{
89 if (!fbc->counters)
90 return;
91
86 free_percpu(fbc->counters); 92 free_percpu(fbc->counters);
87#ifdef CONFIG_HOTPLUG_CPU 93#ifdef CONFIG_HOTPLUG_CPU
88 mutex_lock(&percpu_counters_lock); 94 mutex_lock(&percpu_counters_lock);