Commit 420d0318 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

rtnetlink: remove a level of indentation in rtnl_newlink()

rtnl_newlink() used to create VLAs based on link kind.  Since
commit ccf8dbcd ("rtnetlink: Remove VLA usage") statically
sized array is created on the stack, so there is no more use
for a separate code block that used to be the VLA's live range.

While at it christmas tree the variables.  Note that there is
a goto-based retry so to be on the safe side the variables can
no longer be initialized in place.  It doesn't seem to matter,
logically, but why make the code harder to read..
Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: default avatarDavid Ahern <dsahern@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 74315c39
......@@ -2974,17 +2974,22 @@ static int rtnl_group_changelink(const struct sk_buff *skb,
static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
struct netlink_ext_ack *extack)
{
struct nlattr *slave_attr[RTNL_SLAVE_MAX_TYPE + 1];
unsigned char name_assign_type = NET_NAME_USER;
struct nlattr *linkinfo[IFLA_INFO_MAX + 1];
const struct rtnl_link_ops *m_ops = NULL;
struct nlattr *attr[RTNL_MAX_TYPE + 1];
struct net_device *master_dev = NULL;
struct net *net = sock_net(skb->sk);
const struct rtnl_link_ops *ops;
const struct rtnl_link_ops *m_ops = NULL;
struct nlattr *tb[IFLA_MAX + 1];
struct net *dest_net, *link_net;
struct nlattr **slave_data;
char kind[MODULE_NAME_LEN];
struct net_device *dev;
struct net_device *master_dev = NULL;
struct ifinfomsg *ifm;
char kind[MODULE_NAME_LEN];
char ifname[IFNAMSIZ];
struct nlattr *tb[IFLA_MAX+1];
struct nlattr *linkinfo[IFLA_INFO_MAX+1];
unsigned char name_assign_type = NET_NAME_USER;
struct nlattr **data;
int err;
#ifdef CONFIG_MODULES
......@@ -3040,13 +3045,7 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
ops = NULL;
}
if (1) {
struct nlattr *attr[RTNL_MAX_TYPE + 1];
struct nlattr *slave_attr[RTNL_SLAVE_MAX_TYPE + 1];
struct nlattr **data = NULL;
struct nlattr **slave_data = NULL;
struct net *dest_net, *link_net = NULL;
data = NULL;
if (ops) {
if (ops->maxtype > RTNL_MAX_TYPE)
return -EINVAL;
......@@ -3066,17 +3065,16 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
}
}
slave_data = NULL;
if (m_ops) {
if (m_ops->slave_maxtype > RTNL_SLAVE_MAX_TYPE)
return -EINVAL;
if (m_ops->slave_maxtype &&
linkinfo[IFLA_INFO_SLAVE_DATA]) {
err = nla_parse_nested(slave_attr,
m_ops->slave_maxtype,
err = nla_parse_nested(slave_attr, m_ops->slave_maxtype,
linkinfo[IFLA_INFO_SLAVE_DATA],
m_ops->slave_policy,
extack);
m_ops->slave_policy, extack);
if (err < 0)
return err;
slave_data = slave_attr;
......@@ -3106,16 +3104,14 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
if (!m_ops || !m_ops->slave_changelink)
return -EOPNOTSUPP;
err = m_ops->slave_changelink(master_dev, dev,
tb, slave_data,
extack);
err = m_ops->slave_changelink(master_dev, dev, tb,
slave_data, extack);
if (err < 0)
return err;
status |= DO_SETLINK_NOTIFY;
}
return do_setlink(skb, dev, ifm, extack, tb, ifname,
status);
return do_setlink(skb, dev, ifm, extack, tb, ifname, status);
}
if (!(nlh->nlmsg_flags & NLM_F_CREATE)) {
......@@ -3168,6 +3164,8 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
err = -EPERM;
if (!netlink_ns_capable(skb, link_net->user_ns, CAP_NET_ADMIN))
goto out;
} else {
link_net = NULL;
}
dev = rtnl_create_link(link_net ? : dest_net, ifname,
......@@ -3180,8 +3178,7 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
dev->ifindex = ifm->ifi_index;
if (ops->newlink) {
err = ops->newlink(link_net ? : net, dev, tb, data,
extack);
err = ops->newlink(link_net ? : net, dev, tb, data, extack);
/* Drivers should call free_netdev() in ->destructor
* and unregister it on failure after registration
* so that device could be finally freed in rtnl_unlock.
......@@ -3208,8 +3205,7 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
goto out_unregister;
}
if (tb[IFLA_MASTER]) {
err = do_set_master(dev, nla_get_u32(tb[IFLA_MASTER]),
extack);
err = do_set_master(dev, nla_get_u32(tb[IFLA_MASTER]), extack);
if (err)
goto out_unregister;
}
......@@ -3228,7 +3224,6 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
unregister_netdevice(dev);
}
goto out;
}
}
static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr *nlh,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment