aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Ahern <dsa@cumulusnetworks.com>2018-03-30 12:28:51 -0400
committerDavid S. Miller <davem@davemloft.net>2018-03-31 22:22:10 -0400
commitef817102586cca428d6fe0803cc232a3c929141f (patch)
tree1d5332f50fa0b68efc2b950b4bd834eb4cf1b156
parent6851cf28db1c4becc25a2906ecd080c0022a9f11 (diff)
netdevsim: Change nsim_devlink_setup to return error to caller
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>
-rw-r--r--drivers/net/netdevsim/devlink.c12
-rw-r--r--drivers/net/netdevsim/netdev.c6
-rw-r--r--drivers/net/netdevsim/netdevsim.h5
3 files changed, 15 insertions, 8 deletions
diff --git a/drivers/net/netdevsim/devlink.c b/drivers/net/netdevsim/devlink.c
index bbdcf064ba10..27ae05c5fdaf 100644
--- a/drivers/net/netdevsim/devlink.c
+++ b/drivers/net/netdevsim/devlink.c
@@ -218,22 +218,22 @@ void nsim_devlink_teardown(struct netdevsim *ns)
218 } 218 }
219} 219}
220 220
221void nsim_devlink_setup(struct netdevsim *ns) 221int nsim_devlink_setup(struct netdevsim *ns)
222{ 222{
223 struct net *net = nsim_to_net(ns); 223 struct net *net = nsim_to_net(ns);
224 bool *reg_devlink = net_generic(net, nsim_devlink_id); 224 bool *reg_devlink = net_generic(net, nsim_devlink_id);
225 struct devlink *devlink; 225 struct devlink *devlink;
226 int err = -ENOMEM; 226 int err;
227 227
228 /* only one device per namespace controls devlink */ 228 /* only one device per namespace controls devlink */
229 if (!*reg_devlink) { 229 if (!*reg_devlink) {
230 ns->devlink = NULL; 230 ns->devlink = NULL;
231 return; 231 return 0;
232 } 232 }
233 233
234 devlink = devlink_alloc(&nsim_devlink_ops, 0); 234 devlink = devlink_alloc(&nsim_devlink_ops, 0);
235 if (!devlink) 235 if (!devlink)
236 return; 236 return -ENOMEM;
237 237
238 err = devlink_register(devlink, &ns->dev); 238 err = devlink_register(devlink, &ns->dev);
239 if (err) 239 if (err)
@@ -247,12 +247,14 @@ void nsim_devlink_setup(struct netdevsim *ns)
247 247
248 *reg_devlink = false; 248 *reg_devlink = false;
249 249
250 return; 250 return 0;
251 251
252err_dl_unregister: 252err_dl_unregister:
253 devlink_unregister(devlink); 253 devlink_unregister(devlink);
254err_devlink_free: 254err_devlink_free:
255 devlink_free(devlink); 255 devlink_free(devlink);
256
257 return err;
256} 258}
257 259
258/* Initialize per network namespace state */ 260/* Initialize per network namespace state */
diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c
index 8b30ab3ea2c2..ec68f38213d9 100644
--- a/drivers/net/netdevsim/netdev.c
+++ b/drivers/net/netdevsim/netdev.c
@@ -167,10 +167,14 @@ static int nsim_init(struct net_device *dev)
167 167
168 SET_NETDEV_DEV(dev, &ns->dev); 168 SET_NETDEV_DEV(dev, &ns->dev);
169 169
170 nsim_devlink_setup(ns); 170 err = nsim_devlink_setup(ns);
171 if (err)
172 goto err_unreg_dev;
171 173
172 return 0; 174 return 0;
173 175
176err_unreg_dev:
177 device_unregister(&ns->dev);
174err_bpf_uninit: 178err_bpf_uninit:
175 nsim_bpf_uninit(ns); 179 nsim_bpf_uninit(ns);
176err_debugfs_destroy: 180err_debugfs_destroy:
diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h
index afb8cf90c0fd..3a8581af3b85 100644
--- a/drivers/net/netdevsim/netdevsim.h
+++ b/drivers/net/netdevsim/netdevsim.h
@@ -117,7 +117,7 @@ enum nsim_resource_id {
117 NSIM_RESOURCE_IPV6_FIB_RULES, 117 NSIM_RESOURCE_IPV6_FIB_RULES,
118}; 118};
119 119
120void nsim_devlink_setup(struct netdevsim *ns); 120int nsim_devlink_setup(struct netdevsim *ns);
121void nsim_devlink_teardown(struct netdevsim *ns); 121void nsim_devlink_teardown(struct netdevsim *ns);
122 122
123int nsim_devlink_init(void); 123int nsim_devlink_init(void);
@@ -128,8 +128,9 @@ void nsim_fib_exit(void);
128u64 nsim_fib_get_val(struct net *net, enum nsim_resource_id res_id, bool max); 128u64 nsim_fib_get_val(struct net *net, enum nsim_resource_id res_id, bool max);
129int nsim_fib_set_max(struct net *net, enum nsim_resource_id res_id, u64 val); 129int nsim_fib_set_max(struct net *net, enum nsim_resource_id res_id, u64 val);
130#else 130#else
131static inline void nsim_devlink_setup(struct netdevsim *ns) 131static inline int nsim_devlink_setup(struct netdevsim *ns)
132{ 132{
133 return 0;
133} 134}
134 135
135static inline void nsim_devlink_teardown(struct netdevsim *ns) 136static inline void nsim_devlink_teardown(struct netdevsim *ns)