netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ben Whitten <ben.whitten@gmail.com>
To: afaerber@suse.de, starnight@g.ncu.edu.tw, hasnain.virk@arm.com
Cc: netdev@vger.kernel.org, Ben Whitten <ben.whitten@lairdtech.com>
Subject: [PATCH lora-next 02/10] net: lora: add methods for devm registration
Date: Tue,  7 Aug 2018 18:32:03 +0100	[thread overview]
Message-ID: <1533663131-16313-4-git-send-email-ben.whitten@gmail.com> (raw)
In-Reply-To: <1533663131-16313-1-git-send-email-ben.whitten@gmail.com>

From: Ben Whitten <ben.whitten@lairdtech.com>

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   | 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

  parent reply	other threads:[~2018-08-07 19:47 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-07 17:32 [PATCH lora-next 00/10] Conversing sx1301 to regmap and regfield Ben Whitten
2018-08-07 17:32 ` [PATCH lora-next 01/10] net: lora: sx1301: add register, bit-fields, and helpers for regmap Ben Whitten
2018-08-08  8:57   ` Andreas Färber
2018-08-08 12:32     ` Ben Whitten
2018-08-08 12:51       ` Andreas Färber
2018-08-08 15:52         ` Ben Whitten
2018-08-08 23:37           ` Andreas Färber
2018-08-09 13:23             ` Ben Whitten
2018-08-10 11:37               ` Andreas Färber
2018-08-08  9:07   ` Andreas Färber
2018-08-08 12:24     ` Ben Whitten
2018-08-07 17:32 ` [RFC] spi: add spi multiplexing functions for dt Ben Whitten
2018-08-07 21:17   ` Andreas Färber
2018-08-07 22:03     ` Ben Whitten
2018-08-07 17:32 ` Ben Whitten [this message]
2018-08-07 21:25   ` [PATCH lora-next 02/10] net: lora: add methods for devm registration Andreas Färber
2018-08-07 17:32 ` [PATCH lora-next 03/10] net: lora: sx1301: convert to devm registration of netdev Ben Whitten
2018-08-08  9:00   ` Andreas Färber
2018-08-07 17:32 ` [PATCH lora-next 04/10] net: lora: sx1301: convert probe function to regmap access Ben Whitten
2018-08-07 17:32 ` [PATCH lora-next 05/10] net: lora: sx1301: add device to private data and convert ram reads Ben Whitten
2018-08-07 17:32 ` [PATCH lora-next 06/10] net: lora: sx1301: simplify firmware loading and convert Ben Whitten
2018-08-07 17:32 ` [PATCH lora-next 07/10] net: lora: sx1301: convert read and write burst to take priv data Ben Whitten
2018-08-07 17:32 ` [PATCH lora-next 08/10] net: lora: sx1301: convert read and write to priv pointer Ben Whitten
2018-08-07 17:32 ` [PATCH lora-next 09/10] net: lora: sx1301: convert agc calibrate to regmap functions Ben Whitten
2018-08-07 17:32 ` [PATCH lora-next 10/10] net: lora: sx1301: convert all firmware to regmap Ben Whitten

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=1533663131-16313-4-git-send-email-ben.whitten@gmail.com \
    --to=ben.whitten@gmail.com \
    --cc=afaerber@suse.de \
    --cc=ben.whitten@lairdtech.com \
    --cc=hasnain.virk@arm.com \
    --cc=netdev@vger.kernel.org \
    --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).