netdevsim: Change nsim_devlink_setup to return error to caller
authorDavid Ahern <dsa@cumulusnetworks.com>
Fri, 30 Mar 2018 16:28:51 +0000 (09:28 -0700)
committerDavid S. Miller <davem@davemloft.net>
Sun, 1 Apr 2018 02:22:10 +0000 (22:22 -0400)
Change nsim_devlink_setup to return any error back to the caller and
update nsim_init to handle it.

Requested-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/netdevsim/devlink.c
drivers/net/netdevsim/netdev.c
drivers/net/netdevsim/netdevsim.h

index bbdcf06..27ae05c 100644 (file)
@@ -218,22 +218,22 @@ void nsim_devlink_teardown(struct netdevsim *ns)
        }
 }
 
-void nsim_devlink_setup(struct netdevsim *ns)
+int nsim_devlink_setup(struct netdevsim *ns)
 {
        struct net *net = nsim_to_net(ns);
        bool *reg_devlink = net_generic(net, nsim_devlink_id);
        struct devlink *devlink;
-       int err = -ENOMEM;
+       int err;
 
        /* only one device per namespace controls devlink */
        if (!*reg_devlink) {
                ns->devlink = NULL;
-               return;
+               return 0;
        }
 
        devlink = devlink_alloc(&nsim_devlink_ops, 0);
        if (!devlink)
-               return;
+               return -ENOMEM;
 
        err = devlink_register(devlink, &ns->dev);
        if (err)
@@ -247,12 +247,14 @@ void nsim_devlink_setup(struct netdevsim *ns)
 
        *reg_devlink = false;
 
-       return;
+       return 0;
 
 err_dl_unregister:
        devlink_unregister(devlink);
 err_devlink_free:
        devlink_free(devlink);
+
+       return err;
 }
 
 /* Initialize per network namespace state */
index 8b30ab3..ec68f38 100644 (file)
@@ -167,10 +167,14 @@ static int nsim_init(struct net_device *dev)
 
        SET_NETDEV_DEV(dev, &ns->dev);
 
-       nsim_devlink_setup(ns);
+       err = nsim_devlink_setup(ns);
+       if (err)
+               goto err_unreg_dev;
 
        return 0;
 
+err_unreg_dev:
+       device_unregister(&ns->dev);
 err_bpf_uninit:
        nsim_bpf_uninit(ns);
 err_debugfs_destroy:
index afb8cf9..3a8581a 100644 (file)
@@ -117,7 +117,7 @@ enum nsim_resource_id {
        NSIM_RESOURCE_IPV6_FIB_RULES,
 };
 
-void nsim_devlink_setup(struct netdevsim *ns);
+int nsim_devlink_setup(struct netdevsim *ns);
 void nsim_devlink_teardown(struct netdevsim *ns);
 
 int nsim_devlink_init(void);
@@ -128,8 +128,9 @@ void nsim_fib_exit(void);
 u64 nsim_fib_get_val(struct net *net, enum nsim_resource_id res_id, bool max);
 int nsim_fib_set_max(struct net *net, enum nsim_resource_id res_id, u64 val);
 #else
-static inline void nsim_devlink_setup(struct netdevsim *ns)
+static inline int nsim_devlink_setup(struct netdevsim *ns)
 {
+       return 0;
 }
 
 static inline void nsim_devlink_teardown(struct netdevsim *ns)