lib: percpu_counter_init error handling
[firefly-linux-kernel-4.4.55.git] / lib / percpu_counter.c
index 3b0ed80c1efd1e62914f958393855d44720ee0c7..3a59d84b2d1e14ef96c4ef6f51e939cdc88e574c 100644 (file)
@@ -68,21 +68,27 @@ s64 __percpu_counter_sum(struct percpu_counter *fbc)
 }
 EXPORT_SYMBOL(__percpu_counter_sum);
 
-void percpu_counter_init(struct percpu_counter *fbc, s64 amount)
+int percpu_counter_init(struct percpu_counter *fbc, s64 amount)
 {
        spin_lock_init(&fbc->lock);
        fbc->count = amount;
        fbc->counters = alloc_percpu(s32);
+       if (!fbc->counters)
+               return -ENOMEM;
 #ifdef CONFIG_HOTPLUG_CPU
        mutex_lock(&percpu_counters_lock);
        list_add(&fbc->list, &percpu_counters);
        mutex_unlock(&percpu_counters_lock);
 #endif
+       return 0;
 }
 EXPORT_SYMBOL(percpu_counter_init);
 
 void percpu_counter_destroy(struct percpu_counter *fbc)
 {
+       if (!fbc->counters)
+               return;
+
        free_percpu(fbc->counters);
 #ifdef CONFIG_HOTPLUG_CPU
        mutex_lock(&percpu_counters_lock);