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: <20110312223227.27020.83925.stgit@otae.warmcat.com>
Date:	Sat, 12 Mar 2011 22:32:27 +0000
From:	Andy Green <andy@...mcat.com>
To:	linux-kernel@...r.kernel.org, linux-usb@...r.kernel.org
Cc:	patches@...aro.org, Andy Green <andy.green@...aro.org>
Subject: [RFC PATCH 3/4] PLATFORM: Introduce async platform_data attach api

This introduces a platform API so busses can allow platform_data to
be attached to any struct device they create from probing in one step.

The function checks through the async platform_data map if one was
previously registered, and checks the device's device path for itself
and its parents against the mapped device path names.

If it sees a match, it attaches the associated platform_data and sets
that map entry's device_path to NULL so no further time is spent trying
to match it.

Signed-off-by: Andy Green <andy.green@...aro.org>
---

 drivers/base/platform.c         |   70 +++++++++++++++++++++++++++++++++++++++
 include/linux/platform_device.h |    2 +
 2 files changed, 72 insertions(+), 0 deletions(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 180e372..534bf3a 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -1353,3 +1353,73 @@ void platform_async_platform_data_register(
 	platform_async_platform_data_count = count;
 }
 EXPORT_SYMBOL_GPL(platform_async_platform_data_register);
+
+/**
+ * platform_async_platform_data_attach - if there is any async devname map
+ *			defined, go through it looking for a match with the
+ *			device's path considering its parent device names.
+ *			If a match is found, attach the corresponding
+ *			platform_data and the entry in the map table set to
+ *			NULL so it won't be looked for again.
+ *
+ * @dev:	device to have data attched to if it matches any map entry
+ */
+void platform_async_platform_data_attach(struct device *dev)
+{
+	struct platform_async_platform_data *map;
+	const char *path;
+	int count;
+	const char *p;
+	int len;
+	struct device *devn;
+
+	map = platform_async_platform_data_map;
+	count = platform_async_platform_data_count;
+
+	while (count--) {
+
+		if (map->device_path == NULL) {
+			map++;
+			continue;
+		}
+
+		p = map->device_path + strlen(map->device_path);
+		devn = dev;
+
+		while (devn) {
+
+			path = dev_name(devn);
+			len = strlen(path);
+
+			if ((p - map->device_path) < len) {
+				devn = NULL;
+				continue;
+			}
+
+			p -= len;
+
+			if (strncmp(path, p, len)) {
+				devn = NULL;
+				continue;
+			}
+
+			devn = devn->parent;
+			if (p == map->device_path) {
+				dev_info(dev, "Attched async platform data\n");
+				dev->platform_data = map->platform_data;
+				map->device_path = NULL;
+				return;
+			}
+
+			if (devn != NULL && (p - map->device_path) < 2)
+				devn = NULL;
+
+			p--;
+			if (devn != NULL && *p != '/')
+				devn = NULL;
+		}
+
+		map++;
+	}
+}
+EXPORT_SYMBOL_GPL(platform_async_platform_data_attach);
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 19ea497..4b5fa12 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -213,4 +213,6 @@ struct platform_async_platform_data {
 extern void platform_async_platform_data_register(
 			   struct platform_async_platform_data *map, int count);
 
+extern void platform_async_platform_data_attach(struct device *dev);
+
 #endif /* _PLATFORM_DEVICE_H_ */

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