[PATCH] netlink: switch net_ns only if net is not init_net

From: Gu Zheng
Date: Fri Mar 07 2014 - 05:56:24 EST


Many netlink users create netlink sock in the init_net, and the
switching nes_ns(init_net-->net) is needless in this case. So here
we add a pre-check to avoid this.

Signed-off-by: Gu Zheng <guz.fnst@xxxxxxxxxxxxxx>
---
net/netlink/af_netlink.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index fdf5135..e9e4be9 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -2429,7 +2429,8 @@ __netlink_kernel_create(struct net *net, int unit, struct module *module,
goto out_sock_release_nosk;

sk = sock->sk;
- sk_change_net(sk, net);
+ if (!net_eq(net, &init_net))
+ sk_change_net(sk, net);

if (!cfg || cfg->groups < 32)
groups = 32;
--
1.7.7

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/