aboutsummaryrefslogtreecommitdiffstats
path: root/lib/percpu_counter.c
diff options
context:
space:
mode:
authorPeter Zijlstra <a.p.zijlstra@chello.nl>2007-10-17 02:25:45 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-17 11:42:44 -0400
commit833f4077bf7c2dcff6e31526e03ec2ad91c88581 (patch)
tree80916540be846267342c3e5e4a6255c2c18b44d5 /lib/percpu_counter.c
parentbf1d89c81352f6eca72d0c10cfee3dba29ef5efb (diff)
lib: percpu_counter_init error handling
alloc_percpu can fail, propagate that error. Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
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);