public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Gu Zheng <guz.fnst@cn.fujitsu.com>
To: "David S. Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org, linux-kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH] netlink: switch net_ns only if net is not init_net
Date: Fri, 07 Mar 2014 18:47:30 +0800	[thread overview]
Message-ID: <5319A3C2.8080001@cn.fujitsu.com> (raw)

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@cn.fujitsu.com>
---
 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


             reply	other threads:[~2014-03-07 10:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-07 10:47 Gu Zheng [this message]
2014-03-09 23:09 ` [PATCH] netlink: switch net_ns only if net is not init_net David Miller
2014-03-10  1:11   ` Gu Zheng
2014-03-10  1:57   ` [PATCH] net: add a pre-check of net_ns in sk_change_net() Gu Zheng
2014-03-10 20:30     ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5319A3C2.8080001@cn.fujitsu.com \
    --to=guz.fnst@cn.fujitsu.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox