From: Ben Whitten <ben.whit...@lairdtech.com> Follow the devm model so that we can avoid lengthy unwind code.
Signed-off-by: Ben Whitten <ben.whit...@lairdtech.com> --- drivers/net/lora/dev.c | 20 ++++++++++++++++++++ include/linux/lora/dev.h | 1 + 2 files changed, 21 insertions(+) diff --git a/drivers/net/lora/dev.c b/drivers/net/lora/dev.c index 8c01106..69a8b52 100644 --- a/drivers/net/lora/dev.c +++ b/drivers/net/lora/dev.c @@ -84,6 +84,26 @@ void free_loradev(struct net_device *dev) } EXPORT_SYMBOL_GPL(free_loradev); +static void devm_lora_unregister(struct device *dev, void *res) +{ + free_loradev(*(struct net_device **)res); +} + +int devm_lora_register_netdev(struct device *dev, struct net_device *net) +{ + struct net_device **ptr; + + ptr = devres_alloc(devm_lora_unregister, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return -ENOMEM; + + *ptr = net; + devres_add(dev, ptr); + + return 0; +} +EXPORT_SYMBOL_GPL(devm_lora_register_netdev); + static struct rtnl_link_ops lora_link_ops __read_mostly = { .kind = "lora", .setup = lora_setup, diff --git a/include/linux/lora/dev.h b/include/linux/lora/dev.h index 153f9b2..3f871c6 100644 --- a/include/linux/lora/dev.h +++ b/include/linux/lora/dev.h @@ -32,6 +32,7 @@ static inline int lora_strtoeui(const char *str, lora_eui *val) struct net_device *alloc_loradev(int sizeof_priv); void free_loradev(struct net_device *dev); +int devm_lora_register_netdev(struct device *dev, struct net_device *net); int register_loradev(struct net_device *dev); void unregister_loradev(struct net_device *dev); int open_loradev(struct net_device *dev); -- 2.7.4