Skip to content

Commit a917143

Browse files
author
Al Viro
committed
percpu_ref_init(): clean ->percpu_count_ref on failure
That way percpu_ref_exit() is safe after failing percpu_ref_init(). At least one user (cgroup_create()) had a double-free that way; there might be other similar bugs. Easier to fix in percpu_ref_init(), rather than playing whack-a-mole in sloppy users... Usual symptoms look like a messed refcounting in one of subsystems that use percpu allocations (might be percpu-refcount, might be something else). Having refcounts for two different objects share memory is Not Nice(tm)... Reported-by: [email protected] Signed-off-by: Al Viro <[email protected]>
1 parent feb9c5e commit a917143

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

lib/percpu-refcount.c

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ int percpu_ref_init(struct percpu_ref *ref, percpu_ref_func_t *release,
7676
data = kzalloc(sizeof(*ref->data), gfp);
7777
if (!data) {
7878
free_percpu((void __percpu *)ref->percpu_count_ptr);
79+
ref->percpu_count_ptr = 0;
7980
return -ENOMEM;
8081
}
8182

0 commit comments

Comments
 (0)