[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1533818018-29005-1-git-send-email-ben.whitten@lairdtech.com>
Date: Thu, 9 Aug 2018 13:33:31 +0100
From: Ben Whitten <ben.whitten@...il.com>
To: afaerber@...e.de
Cc: starnight@...cu.edu.tw, hasnain.virk@....com,
netdev@...r.kernel.org, liuxuenetmail@...il.com, shess@...sware.de,
Ben Whitten <ben.whitten@...rdtech.com>
Subject: [PATCH lora-next v2 1/8] net: lora: add methods for devm registration
Follow the devm model so that we can avoid lengthy unwind code.
Signed-off-by: Ben Whitten <ben.whitten@...rdtech.com>
---
drivers/net/lora/dev.c | 28 ++++++++++++++++++++++++++++
include/linux/lora/dev.h | 1 +
2 files changed, 29 insertions(+)
diff --git a/drivers/net/lora/dev.c b/drivers/net/lora/dev.c
index 8c01106..e32a870 100644
--- a/drivers/net/lora/dev.c
+++ b/drivers/net/lora/dev.c
@@ -84,6 +84,34 @@ void free_loradev(struct net_device *dev)
}
EXPORT_SYMBOL_GPL(free_loradev);
+static void devm_free_loradev(struct device *dev, void *res)
+{
+ struct net_device *net = (*(struct net_device **)res);
+ free_loradev(net);
+}
+
+struct net_device *devm_alloc_loradev(struct device *dev, size_t priv)
+{
+ struct net_device **ptr;
+ struct net_device *net;
+
+ net = alloc_loradev(priv);
+ if (!net)
+ return NULL;
+
+ ptr = devres_alloc(devm_free_loradev, sizeof(*ptr), GFP_KERNEL);
+ if (!ptr) {
+ free_loradev(net);
+ return NULL;
+ }
+
+ *ptr = net;
+ devres_add(dev, ptr);
+
+ return net;
+}
+EXPORT_SYMBOL_GPL(devm_alloc_loradev);
+
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..0f600c9 100644
--- a/include/linux/lora/dev.h
+++ b/include/linux/lora/dev.h
@@ -31,6 +31,7 @@ static inline int lora_strtoeui(const char *str, lora_eui *val)
}
struct net_device *alloc_loradev(int sizeof_priv);
+struct net_device *devm_alloc_loradev(struct device *dev, size_t priv);
void free_loradev(struct net_device *dev);
int register_loradev(struct net_device *dev);
void unregister_loradev(struct net_device *dev);
--
2.7.4
Powered by blists - more mailing lists