[PATCH NET-PREV 01/51] net: Move some checks from __rtnl_newlink() to caller

Kirill Tkhai posted 51 patches 9 months ago
[PATCH NET-PREV 01/51] net: Move some checks from __rtnl_newlink() to caller
Posted by Kirill Tkhai 9 months ago
The patch is preparation in rtnetlink code for using nd_lock.
This is a step to move dereference of tb[IFLA_MASTER] up
to where main dev is dereferenced by ifi_index.

Signed-off-by: Kirill Tkhai <tkhai@ya.ru>
---
 net/core/rtnetlink.c |   21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 73fd7f543fd0..b33a7e86c534 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -3572,15 +3572,6 @@ static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
 #ifdef CONFIG_MODULES
 replay:
 #endif
-	err = nlmsg_parse_deprecated(nlh, sizeof(*ifm), tb, IFLA_MAX,
-				     ifla_policy, extack);
-	if (err < 0)
-		return err;
-
-	err = rtnl_ensure_unique_netns(tb, extack, false);
-	if (err < 0)
-		return err;
-
 	ifm = nlmsg_data(nlh);
 	if (ifm->ifi_index > 0) {
 		link_specified = true;
@@ -3734,13 +3725,25 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
 			struct netlink_ext_ack *extack)
 {
 	struct rtnl_newlink_tbs *tbs;
+	struct nlattr **tb;
 	int ret;
 
 	tbs = kmalloc(sizeof(*tbs), GFP_KERNEL);
 	if (!tbs)
 		return -ENOMEM;
+	tb = tbs->tb;
+
+	ret = nlmsg_parse_deprecated(nlh, sizeof(struct ifinfomsg), tb,
+				     IFLA_MAX, ifla_policy, extack);
+	if (ret < 0)
+		goto out;
+
+	ret = rtnl_ensure_unique_netns(tb, extack, false);
+	if (ret < 0)
+		goto out;
 
 	ret = __rtnl_newlink(skb, nlh, tbs, extack);
+out:
 	kfree(tbs);
 	return ret;
 }