From: Ben Whitten <ben.whitten@gmail.com>
To: afaerber@suse.de
Cc: starnight@g.ncu.edu.tw, hasnain.virk@arm.com,
netdev@vger.kernel.org, liuxuenetmail@gmail.com,
shess@hessware.de, Ben Whitten <ben.whitten@lairdtech.com>
Subject: [PATCH lora-next v2 1/8] net: lora: add methods for devm registration
Date: Thu, 9 Aug 2018 13:33:31 +0100 [thread overview]
Message-ID: <1533818018-29005-1-git-send-email-ben.whitten@lairdtech.com> (raw)
Follow the devm model so that we can avoid lengthy unwind code.
Signed-off-by: Ben Whitten <ben.whitten@lairdtech.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
next reply other threads:[~2018-08-09 14:59 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-09 12:33 Ben Whitten [this message]
2018-08-09 12:33 ` [PATCH lora-next v2 2/8] net: lora: sx1301: convert to devm registration of netdev Ben Whitten
2018-08-09 19:27 ` Andreas Färber
2018-08-09 12:33 ` [PATCH lora-next v2 3/8] net: lora: sx1301: convert to passing priv data throughout Ben Whitten
2018-08-09 20:43 ` Andreas Färber
2018-08-09 21:06 ` Ben Whitten
2018-08-09 21:21 ` Andreas Färber
2018-08-09 12:33 ` [PATCH lora-next v2 4/8] net: lora: sx1301: convert load_firmware to take firmware directly Ben Whitten
2018-08-09 20:48 ` Andreas Färber
2018-08-09 12:33 ` [PATCH lora-next v2 5/8] net: lora: sx1301: remove duplicate firmware size checks Ben Whitten
2018-08-09 20:58 ` Andreas Färber
2018-08-09 12:33 ` [PATCH lora-next v2 6/8] net: lora: sx1301: replace version and size magic numbers with defines Ben Whitten
2018-08-09 21:11 ` Andreas Färber
2018-08-09 12:33 ` [PATCH lora-next v2 7/8] net: lora: sx1301: add initial registration for regmap Ben Whitten
2018-08-09 21:58 ` Andreas Färber
2018-08-09 12:33 ` [PATCH lora-next v2 8/8] net: lora: sx1301: convert driver over to regmap reads and writes Ben Whitten
2018-08-09 22:34 ` Andreas Färber
2018-08-09 22:47 ` Ben Whitten
2018-08-10 0:17 ` Andreas Färber
2018-08-09 19:18 ` [PATCH lora-next v2 1/8] net: lora: add methods for devm registration Andreas Färber
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1533818018-29005-1-git-send-email-ben.whitten@lairdtech.com \
--to=ben.whitten@gmail.com \
--cc=afaerber@suse.de \
--cc=ben.whitten@lairdtech.com \
--cc=hasnain.virk@arm.com \
--cc=liuxuenetmail@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=shess@hessware.de \
--cc=starnight@g.ncu.edu.tw \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).