netdevsim: rename dev_init/exit() functions and make them independent on ns
authorJiri Pirko <jiri@mellanox.com>
Thu, 25 Apr 2019 13:59:49 +0000 (15:59 +0200)
committerDavid S. Miller <davem@davemloft.net>
Fri, 26 Apr 2019 05:52:02 +0000 (01:52 -0400)
These functions are going to be called from bus probe/release(),
therefore make them independent on ns struct and rename accordingly.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/netdevsim/dev.c
drivers/net/netdevsim/netdev.c
drivers/net/netdevsim/netdevsim.h

index c83c08edf94fc0f7b1609940c9c88114d90cd6df..664b9329a65ca59473cfd23164f58188b6df0815 100644 (file)
 
 #include "netdevsim.h"
 
-struct nsim_dev {
-       struct nsim_fib_data *fib_data;
-};
-
 static u64 nsim_dev_ipv4_fib_resource_occ_get(void *priv)
 {
        struct nsim_dev *nsim_dev = priv;
@@ -178,7 +174,7 @@ static const struct devlink_ops nsim_dev_devlink_ops = {
        .reload = nsim_dev_reload,
 };
 
-static int __nsim_dev_init(struct netdevsim *ns)
+static struct nsim_dev *nsim_dev_create(struct nsim_bus_dev *nsim_bus_dev)
 {
        struct nsim_dev *nsim_dev;
        struct devlink *devlink;
@@ -186,7 +182,7 @@ static int __nsim_dev_init(struct netdevsim *ns)
 
        devlink = devlink_alloc(&nsim_dev_devlink_ops, sizeof(*nsim_dev));
        if (!devlink)
-               return -ENOMEM;
+               return ERR_PTR(-ENOMEM);
        nsim_dev = devlink_priv(devlink);
 
        nsim_dev->fib_data = nsim_fib_create();
@@ -199,13 +195,11 @@ static int __nsim_dev_init(struct netdevsim *ns)
        if (err)
                goto err_fib_destroy;
 
-       err = devlink_register(devlink, &ns->nsim_bus_dev->dev);
+       err = devlink_register(devlink, &nsim_bus_dev->dev);
        if (err)
                goto err_resources_unregister;
 
-       ns->devlink = devlink;
-
-       return 0;
+       return nsim_dev;
 
 err_resources_unregister:
        devlink_resources_unregister(devlink, NULL);
@@ -213,26 +207,26 @@ err_fib_destroy:
        nsim_fib_destroy(nsim_dev->fib_data);
 err_devlink_free:
        devlink_free(devlink);
-
-       return err;
+       return ERR_PTR(err);
 }
 
-int nsim_dev_init(struct netdevsim *ns)
+struct nsim_dev *
+nsim_dev_create_with_ns(struct nsim_bus_dev *nsim_bus_dev,
+                       struct netdevsim *ns)
 {
-       int err;
+       struct nsim_dev *nsim_dev;
 
        dev_hold(ns->netdev);
        rtnl_unlock();
-       err = __nsim_dev_init(ns);
+       nsim_dev = nsim_dev_create(nsim_bus_dev);
        rtnl_lock();
        dev_put(ns->netdev);
-       return err;
+       return nsim_dev;
 }
 
-void nsim_dev_exit(struct netdevsim *ns)
+void nsim_dev_destroy(struct nsim_dev *nsim_dev)
 {
-       struct devlink *devlink = ns->devlink;
-       struct nsim_dev *nsim_dev = devlink_priv(devlink);
+       struct devlink *devlink = priv_to_devlink(nsim_dev);
 
        devlink_unregister(devlink);
        devlink_resources_unregister(devlink, NULL);
index 37a442ffcb8b722581436473e079b87cefa9df88..28231bfbc989b23abbc55c06da56c44d09e96e19 100644 (file)
@@ -77,7 +77,7 @@ static void nsim_free(struct net_device *dev)
 {
        struct netdevsim *ns = netdev_priv(dev);
 
-       nsim_dev_exit(ns);
+       nsim_dev_destroy(ns->nsim_dev);
        nsim_bus_dev_del(ns->nsim_bus_dev);
        /* netdev and vf state will be freed out of device_release() */
        nsim_sdev_put(ns->sdev);
@@ -395,17 +395,19 @@ static int nsim_newlink(struct net *src_net, struct net_device *dev,
        SET_NETDEV_DEV(dev, &ns->nsim_bus_dev->dev);
        ns->netdev = dev;
 
-       err = nsim_dev_init(ns);
-       if (err)
+       ns->nsim_dev = nsim_dev_create_with_ns(ns->nsim_bus_dev, ns);
+       if (IS_ERR(ns->nsim_dev)) {
+               err = PTR_ERR(ns->nsim_dev);
                goto err_dev_del;
+       }
 
        err = register_netdevice(dev);
        if (err)
-               goto err_dev_exit;
+               goto err_dev_destroy;
        return 0;
 
-err_dev_exit:
-       nsim_dev_exit(ns);
+err_dev_destroy:
+       nsim_dev_destroy(ns->nsim_dev);
 err_dev_del:
        nsim_bus_dev_del(ns->nsim_bus_dev);
 err_sdev_put:
index 8d61fcb55f391516c023c27fb53841d5c7b9e098..d6b3668f9afdeaa9e5b76248f879546a3bf648a1 100644 (file)
@@ -80,6 +80,7 @@ struct nsim_ipsec {
 
 struct netdevsim {
        struct net_device *netdev;
+       struct nsim_dev *nsim_dev;
 
        u64 tx_packets;
        u64 tx_bytes;
@@ -102,7 +103,6 @@ struct netdevsim {
        bool bpf_xdpoffload_accept;
 
        bool bpf_map_accept;
-       struct devlink *devlink;
        struct nsim_ipsec ipsec;
 };
 
@@ -151,8 +151,14 @@ enum nsim_resource_id {
        NSIM_RESOURCE_IPV6_FIB_RULES,
 };
 
-int nsim_dev_init(struct netdevsim *ns);
-void nsim_dev_exit(struct netdevsim *ns);
+struct nsim_dev {
+       struct nsim_fib_data *fib_data;
+};
+
+struct nsim_dev *
+nsim_dev_create_with_ns(struct nsim_bus_dev *nsim_bus_dev,
+                       struct netdevsim *ns);
+void nsim_dev_destroy(struct nsim_dev *nsim_dev);
 
 struct nsim_fib_data *nsim_fib_create(void);
 void nsim_fib_destroy(struct nsim_fib_data *fib_data);