Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1363058 > unrolled thread

[RFC 1/2] misc: Add of_get_misc get a reference from devicetree

Started byMoritz Fischer <moritz.fischer@ettus.com>
First post2016-03-22 23:40 +0100
Last post2016-03-23 00:00 +0100
Articles 2 — 1 participant

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [RFC 1/2] misc: Add of_get_misc get a reference from devicetree Moritz Fischer <moritz.fischer@ettus.com> - 2016-03-22 23:40 +0100
    Re: [RFC 1/2] misc: Add of_get_misc get a reference from devicetree Moritz Fischer <moritz.fischer@ettus.com> - 2016-03-23 00:00 +0100

#1363058 — [RFC 1/2] misc: Add of_get_misc get a reference from devicetree

FromMoritz Fischer <moritz.fischer@ettus.com>
Date2016-03-22 23:40 +0100
Subject[RFC 1/2] misc: Add of_get_misc get a reference from devicetree
Message-ID<rfD7Y-2AF-9@gated-at.bofh.it>
This commit enables access to a miscdevice via a reference
obtained from devicetree.
This allows to implement a of_ion_device_get() in the next step.

Signed-off-by: Moritz Fischer <moritz.fischer@ettus.com>
---
 drivers/char/misc.c        | 38 ++++++++++++++++++++++++++++++++++++++
 include/linux/miscdevice.h |  3 +++
 2 files changed, 41 insertions(+)

diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index 8069b36..0623834 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -275,6 +275,44 @@ static char *misc_devnode(struct device *dev, umode_t *mode)
 	return NULL;
 }
 
+#ifdef CONFIG_OF
+static int misc_of_node_match(struct device *dev, const void *data)
+{
+	return dev->of_node == data;
+}
+
+struct miscdevice *of_misc_get(struct device_node *node)
+{
+	struct miscdevice *m;
+	struct device *dev;
+	int ret = -ENODEV;
+
+	dev = class_find_device(misc_class, NULL, node,
+				misc_of_node_match);
+	if (!dev)
+		return ERR_PTR(-ENODEV);
+
+	m = dev_get_drvdata(dev);
+	if (!m)
+		goto err_dev;
+
+	if (!try_module_get(dev->parent->driver->owner))
+		goto err_dev;
+
+	return m;
+
+err_dev:
+	put_device(dev);
+	return ERR_PTR(ret);
+}
+#else
+struct misc_device *of_misc_get(struct device_node *)
+{
+	return ERR_PTR(-ENODEV);
+}
+#endif
+EXPORT_SYMBOL(of_misc_get);
+
 static int __init misc_init(void)
 {
 	int err;
diff --git a/include/linux/miscdevice.h b/include/linux/miscdevice.h
index 5430374..a4b605c 100644
--- a/include/linux/miscdevice.h
+++ b/include/linux/miscdevice.h
@@ -53,6 +53,7 @@
 #define MISC_DYNAMIC_MINOR	255
 
 struct device;
+struct device_node;
 struct attribute_group;
 
 struct miscdevice  {
@@ -70,6 +71,8 @@ struct miscdevice  {
 extern int misc_register(struct miscdevice *misc);
 extern void misc_deregister(struct miscdevice *misc);
 
+extern struct miscdevice *of_misc_get(struct device_node *node);
+
 #define MODULE_ALIAS_MISCDEV(minor)				\
 	MODULE_ALIAS("char-major-" __stringify(MISC_MAJOR)	\
 	"-" __stringify(minor))
-- 
2.7.4

[toc] | [next] | [standalone]


#1363069

FromMoritz Fischer <moritz.fischer@ettus.com>
Date2016-03-23 00:00 +0100
Message-ID<rfDrk-2Hw-9@gated-at.bofh.it>
In reply to#1363058
Meh,

On Tue, Mar 22, 2016 at 3:33 PM, Moritz Fischer
<moritz.fischer@ettus.com> wrote:

>
> +
> +err_dev:
> +       put_device(dev);
> +       return ERR_PTR(ret);
> +}
> +#else
> +struct misc_device *of_misc_get(struct device_node *)

Ok, that one is broken ....

Sorry,

Moritz

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web