public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] mtd: unify mtd partition/device registration
@ 2008-11-12 23:38 Mike Frysinger
  2008-11-12 23:39 ` [PATCH] mtd/physmap: use parse_mtd() Mike Frysinger
                   ` (4 more replies)
  0 siblings, 5 replies; 17+ messages in thread
From: Mike Frysinger @ 2008-11-12 23:38 UTC (permalink / raw)
  To: linux-mtd, David Woodhouse; +Cc: linux-kernel

Rather than having every map/mtd driver doing the same sequence of
registering partitions and/or devices, implement common parse_mtd().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 drivers/mtd/mtdcore.c   |   37 +++++++++++++++++++++++++++++++++++++
 include/linux/mtd/mtd.h |    3 +++
 2 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index a9d2469..654ec1b 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -292,6 +292,43 @@ void put_mtd_device(struct mtd_info *mtd)
 	module_put(mtd->owner);
 }
 
+#include <linux/mtd/partitions.h>
+
+/**
+ *	parse_mtd - add partitions / devices
+ *
+ *	If partitioning support is enabled, attempt to call parse_mtd_partitions()
+ *	and add_mtd_partitions() with all available parsers.  Otherwise just add
+ *	the MTD device.
+ */
+
+int parse_mtd(struct mtd_info *mtd, const char **probe_types,
+              struct mtd_partition *parts, int nr_parts)
+{
+#ifdef CONFIG_MTD_PARTITIONS
+	const char *default_part_probe_types[] = {
+		"cmdlinepart",
+		"RedBoot",
+		NULL
+	};
+	int ret;
+
+	if (!probe_types)
+		probe_types = default_part_probe_types;
+
+	ret = parse_mtd_partitions(mtd, probe_types, &parts, 0);
+	if (ret > 0) {
+		ret = add_mtd_partitions(mtd, parts, ret);
+		kfree(parts);
+		return ret;
+	} else if (nr_parts)
+		return add_mtd_partitions(mtd, parts, nr_parts);
+#endif
+
+	return add_mtd_device(mtd);
+}
+EXPORT_SYMBOL(parse_mtd);
+
 /* default_mtd_writev - default mtd writev method for MTD devices that
  *			don't implement their own
  */
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index eae26bb..dec3456 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -232,6 +232,9 @@ extern struct mtd_info *get_mtd_device_nm(const char *name);
 
 extern void put_mtd_device(struct mtd_info *mtd);
 
+struct mtd_partition;
+int parse_mtd(struct mtd_info *mtd, const char **probe_types,
+              struct mtd_partition *parts, int nr_parts);
 
 struct mtd_notifier {
 	void (*add)(struct mtd_info *mtd);
-- 
1.6.0.3

^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2008-11-16 18:02 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-12 23:38 [PATCH] mtd: unify mtd partition/device registration Mike Frysinger
2008-11-12 23:39 ` [PATCH] mtd/physmap: use parse_mtd() Mike Frysinger
2008-11-13 13:51   ` Atsushi Nemoto
2008-11-13 14:44     ` Mike Frysinger
2008-11-14 21:41   ` Andrew Morton
2008-11-14 22:07     ` Mike Frysinger
2008-11-12 23:39 ` [PATCH] mtd/bfin-async-flash: " Mike Frysinger
2008-11-13 13:43 ` [PATCH] mtd: unify mtd partition/device registration Atsushi Nemoto
2008-11-13 14:28   ` Atsushi Nemoto
2008-11-13 14:51     ` Mike Frysinger
2008-11-13 15:51       ` Atsushi Nemoto
2008-11-13 15:55         ` Mike Frysinger
2008-11-13 14:47   ` Mike Frysinger
2008-11-14 21:39 ` Andrew Morton
2008-11-16 17:34 ` Jörn Engel
2008-11-16 17:55   ` Mike Frysinger
2008-11-16 18:02     ` Jörn Engel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox