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-next>] [day] [month] [year] [list]
Date:	Tue, 18 Mar 2014 23:52:29 +0200
From:	Pantelis Antoniou <pantelis.antoniou@...sulko.com>
To:	Grant Likely <grant.likely@...retlab.ca>
Cc:	Rob Herring <robherring2@...il.com>,
	Stephen Warren <swarren@...dotorg.org>,
	Matt Porter <matt.porter@...aro.org>,
	Koen Kooi <koen@...inion.thruhere.net>,
	Alison Chaiken <Alison_Chaiken@...tor.com>,
	Dinh Nguyen <dinh.linux@...il.com>,
	Jan Lubbe <jluebbe@...net.de>,
	Alexander Sverdlin <alexander.sverdlin@....com>,
	Michael Stickel <ms@...able.de>,
	Guenter Roeck <linux@...ck-us.net>,
	Dirk Behme <dirk.behme@...il.com>,
	Alan Tull <delicious.quinoa@...il.com>,
	Sascha Hauer <s.hauer@...gutronix.de>,
	Michael Bohan <mbohan@...eaurora.org>,
	Ionut Nicu <ioan.nicu.ext@....com>,
	Michal Simek <monstr@...str.eu>,
	Matt Ranostay <mranostay@...il.com>,
	devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
	Pete Popov <pete.popov@...sulko.com>,
	Dan Malek <dan.malek@...sulko.com>,
	Georgi Vlaev <georgi.vlaev@...sulko.com>,
	Pantelis Antoniou <pantelis.antoniou@...sulko.com>
Subject: [PATCH] of: Make of_find_node_by_path() handle /aliases

Make of_find_node_by_path() handle aliases as prefixes.

Originally by David Daney <ddaney@...iumnetworks.com>, but
reworked according to remark by Grant Likely.

Handles all cases without allocating memory as requested by
Grant Likely <grant.likely@...aro.org>

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@...sulko.com>
---
 drivers/of/base.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 65 insertions(+), 4 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 7083fad..19bcdb4 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -773,22 +773,83 @@ EXPORT_SYMBOL(of_get_child_by_name);
 /**
  *	of_find_node_by_path - Find a node matching a full OF path
  *	@path:	The full path to match
+ *	@path: Either the full path to match, or if the path does not
+ *	       start with '/', the name of a property of the /aliases
+ *	       node (an alias).  In the case of an alias, the node
+ *	       matching the alias' value will be returned.
+ *
+ *	Valid paths:
+ *		/foo/bar	Full path
+ *		foo		Valid alias
+ *		foo/bar		Valid alias + relative path
  *
  *	Returns a node pointer with refcount incremented, use
  *	of_node_put() on it when done.
  */
 struct device_node *of_find_node_by_path(const char *path)
 {
-	struct device_node *np = of_allnodes;
+	struct device_node *np = NULL;
+	int len;
+	const char *p = NULL;
+	struct property *prop;
 	unsigned long flags;
 
+	/* under lock (not very nice) */
 	raw_spin_lock_irqsave(&devtree_lock, flags);
-	for (; np; np = np->allnext) {
-		if (np->full_name && (of_node_cmp(np->full_name, path) == 0)
-		    && of_node_get(np))
+
+	len = strlen(path);
+
+	/* path begins with an alias */
+	if (path[0] != '/') {
+
+		/* now find the relative path (if any)*/
+		p = strchr(path, '/');
+		if (p != NULL)
+			len = p - path;
+
+		/* of_aliases must not be NULL */
+		if (!of_aliases)
+			goto out;
+
+		/* find matching alias */
+		for_each_property_of_node(of_aliases, prop)
+			if (strlen(prop->name) == len &&
+					strncmp(prop->name, path, len) == 0)
+				break;
+
+		/* not found; bail */
+		if (prop == NULL)
+			goto out;
+
+		path = prop->value;
+	}
+
+	/* path lookup */
+	for_each_of_allnodes(np) {
+
+		if (!np->full_name)
+			continue;
+
+		if (p == NULL) {
+			/* full component */
+			if (strcasecmp(np->full_name, path) != 0)
+				continue;
+		} else {
+			/* last component (including '/') */
+			if (strncasecmp(np->full_name, path, len) != 0)
+				continue;
+
+			if (strcasecmp(np->full_name + len, p) != 0)
+				continue;
+		}
+
+		if (of_node_get(np))
 			break;
 	}
+
+out:
 	raw_spin_unlock_irqrestore(&devtree_lock, flags);
+
 	return np;
 }
 EXPORT_SYMBOL(of_find_node_by_path);
-- 
1.7.12

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ