Thread (3 messages) flat view 3 messages, 2 authors, 2021-11-25

Re: [PATCH net-next v2] rtnetlink: Support fine-grained netdevice bulk deletion

From: Lahav Schlesinger <hidden>
Date: 2021-11-25 16:40:02

On Thu, Nov 25, 2021 at 08:06:38AM -0800, Jakub Kicinski wrote:
CAUTION: External E-Mail - Use caution with links and attachments


On Thu, 25 Nov 2021 14:47:13 +0200 Lahav Schlesinger wrote:
quoted
+static int rtnl_list_dellink(struct net *net, void *ifindex_list, int size)
s/ifindex_list/ifindices/ ? it's not really a list

Can we make it an int pointer so we don't have to cast it later?
quoted
+{
+     const int num_devices = size / sizeof(int);
+     struct net_device **dev_list;
+     LIST_HEAD(list_kill);
+     int i, ret;
+
+     if (size < 0 || size % sizeof(int))
Does core reject size == 0? It won't be valid either.
quoted
+             return -EINVAL;
+
+     dev_list = kmalloc_array(num_devices, sizeof(*dev_list), GFP_KERNEL);
+     if (!dev_list)
+             return -ENOMEM;
+
+     for (i = 0; i < num_devices; i++) {
+             const struct rtnl_link_ops *ops;
+             struct net_device *dev;
+
+             ret = -ENODEV;
+             dev = __dev_get_by_index(net, ((int *)ifindex_list)[i]);
+             if (!dev)
+                     goto out_free;
+
+             ret = -EOPNOTSUPP;
+             ops = dev->rtnl_link_ops;
+             if (!ops || !ops->dellink)
+                     goto out_free;
+
+             dev_list[i] = dev;
+     }
+
+     for (i = 0; i < num_devices; i++) {
+             const struct rtnl_link_ops *ops;
+             struct net_device *dev;
the temp variables are unnecessary here, the whole thing comfortably
fits on a line:

                dev->rtnl_link_ops->dellink(dev_list[i], &list_kill);
quoted
+             dev = dev_list[i];
+             ops = dev->rtnl_link_ops;
+             ops->dellink(dev, &list_kill);
+     }
+
+     unregister_netdevice_many(&list_kill);
+
+     ret = 0;
+
+out_free:
+     kfree(dev_list);
+     return ret;
+}
Thanks for the feedback Jakub, I'll send a V3 with your proposed
changes.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help