Skip to content

Commit f49b42d

Browse files
MengEn Sunakpm00
MengEn Sun
authored andcommitted
ucounts: move kfree() out of critical zone protected by ucounts_lock
Although kfree is a non-sleep function, it is possible to enter a long chain of calls probabilistically, so it looks better to move kfree from alloc_ucounts() out of the critical zone of ucounts_lock. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: MengEn Sun <[email protected]> Reviewed-by: YueHong Wu <[email protected]> Reviewed-by: Andrew Morton <[email protected]> Cc: Andrei Vagin <[email protected]> Cc: Joel Granados <[email protected]> Cc: Thomas Weißschuh <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent c7bb5cf commit f49b42d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

kernel/ucount.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ struct ucounts *get_ucounts(struct ucounts *ucounts)
164164
struct ucounts *alloc_ucounts(struct user_namespace *ns, kuid_t uid)
165165
{
166166
struct hlist_head *hashent = ucounts_hashentry(ns, uid);
167-
struct ucounts *ucounts, *new;
168167
bool wrapped;
168+
struct ucounts *ucounts, *new = NULL;
169169

170170
spin_lock_irq(&ucounts_lock);
171171
ucounts = find_ucounts(ns, uid, hashent);
@@ -182,17 +182,17 @@ struct ucounts *alloc_ucounts(struct user_namespace *ns, kuid_t uid)
182182

183183
spin_lock_irq(&ucounts_lock);
184184
ucounts = find_ucounts(ns, uid, hashent);
185-
if (ucounts) {
186-
kfree(new);
187-
} else {
185+
if (!ucounts) {
188186
hlist_add_head(&new->node, hashent);
189187
get_user_ns(new->ns);
190188
spin_unlock_irq(&ucounts_lock);
191189
return new;
192190
}
193191
}
192+
194193
wrapped = !get_ucounts_or_wrap(ucounts);
195194
spin_unlock_irq(&ucounts_lock);
195+
kfree(new);
196196
if (wrapped) {
197197
put_ucounts(ucounts);
198198
return NULL;

0 commit comments

Comments
 (0)