Skip to content

Commit 5ba049a

Browse files
Kirill Tkhaidavem330
authored andcommitted
net: Cleanup in copy_net_ns()
Line up destructors actions in the revers order to constructors. Next patches will add more actions, and this will be comfortable, if there is the such order. Signed-off-by: Kirill Tkhai <[email protected]> Acked-by: Andrei Vagin <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 98f6c53 commit 5ba049a

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

net/core/net_namespace.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -411,27 +411,25 @@ struct net *copy_net_ns(unsigned long flags,
411411

412412
net = net_alloc();
413413
if (!net) {
414-
dec_net_namespaces(ucounts);
415-
return ERR_PTR(-ENOMEM);
414+
rv = -ENOMEM;
415+
goto dec_ucounts;
416416
}
417-
417+
refcount_set(&net->passive, 1);
418+
net->ucounts = ucounts;
418419
get_user_ns(user_ns);
419420

420421
rv = mutex_lock_killable(&net_mutex);
421-
if (rv < 0) {
422-
net_free(net);
423-
dec_net_namespaces(ucounts);
424-
put_user_ns(user_ns);
425-
return ERR_PTR(rv);
426-
}
422+
if (rv < 0)
423+
goto put_userns;
427424

428-
net->ucounts = ucounts;
429425
rv = setup_net(net, user_ns);
430426
mutex_unlock(&net_mutex);
431427
if (rv < 0) {
432-
dec_net_namespaces(ucounts);
428+
put_userns:
433429
put_user_ns(user_ns);
434430
net_drop_ns(net);
431+
dec_ucounts:
432+
dec_net_namespaces(ucounts);
435433
return ERR_PTR(rv);
436434
}
437435
return net;

0 commit comments

Comments
 (0)