lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1458686031-31031-2-git-send-email-moritz.fischer@ettus.com>
Date:	Tue, 22 Mar 2016 15:33:50 -0700
From:	Moritz Fischer <moritz.fischer@...us.com>
To:	arnd@...db.de
Cc:	gregkh@...uxfoundation.org, arve@...roid.com,
	riandrews@...roid.com, labbott@...hat.com, gioh.kim@....com,
	sumit.semwal@...aro.org, dan.carpenter@...cle.com,
	sriram@...irs.net.in, linux-kernel@...r.kernel.org,
	devel@...verdev.osuosl.org,
	Moritz Fischer <moritz.fischer@...us.com>
Subject: [RFC 1/2] misc: Add of_get_misc get a reference from devicetree

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@...us.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ