]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rtnetlink: Clean up rtnl_dellink().
authorKuniyuki Iwashima <kuniyu@amazon.com>
Wed, 16 Oct 2024 18:53:53 +0000 (11:53 -0700)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 22 Oct 2024 09:02:05 +0000 (11:02 +0200)
We will push RTNL down to rtnl_delink().

Let's unify the error path to make it easy to place rtnl_net_lock().

While at it, keep the variables in reverse xmas order.

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
net/core/rtnetlink.c

index eee0f820ddf6b1f9fac1d0bc0eb2d8f77f5ecc41..a19b2eb2727e405a8e6d8955f88e045e159bc21f 100644 (file)
@@ -3368,14 +3368,14 @@ EXPORT_SYMBOL_GPL(rtnl_delete_link);
 static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh,
                        struct netlink_ext_ack *extack)
 {
+       struct ifinfomsg *ifm = nlmsg_data(nlh);
        struct net *net = sock_net(skb->sk);
        u32 portid = NETLINK_CB(skb).portid;
-       struct net *tgt_net = net;
-       struct net_device *dev = NULL;
-       struct ifinfomsg *ifm;
        struct nlattr *tb[IFLA_MAX+1];
-       int err;
+       struct net_device *dev = NULL;
+       struct net *tgt_net = net;
        int netnsid = -1;
+       int err;
 
        err = nlmsg_parse_deprecated(nlh, sizeof(*ifm), tb, IFLA_MAX,
                                     ifla_policy, extack);
@@ -3393,27 +3393,20 @@ static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh,
                        return PTR_ERR(tgt_net);
        }
 
-       err = -EINVAL;
-       ifm = nlmsg_data(nlh);
        if (ifm->ifi_index > 0)
                dev = __dev_get_by_index(tgt_net, ifm->ifi_index);
        else if (tb[IFLA_IFNAME] || tb[IFLA_ALT_IFNAME])
                dev = rtnl_dev_get(tgt_net, tb);
+
+       if (dev)
+               err = rtnl_delete_link(dev, portid, nlh);
+       else if (ifm->ifi_index > 0 || tb[IFLA_IFNAME] || tb[IFLA_ALT_IFNAME])
+               err = -ENODEV;
        else if (tb[IFLA_GROUP])
                err = rtnl_group_dellink(tgt_net, nla_get_u32(tb[IFLA_GROUP]));
        else
-               goto out;
-
-       if (!dev) {
-               if (tb[IFLA_IFNAME] || tb[IFLA_ALT_IFNAME] || ifm->ifi_index > 0)
-                       err = -ENODEV;
-
-               goto out;
-       }
-
-       err = rtnl_delete_link(dev, portid, nlh);
+               err = -EINVAL;
 
-out:
        if (netnsid >= 0)
                put_net(tgt_net);