From patchwork Wed Nov 12 23:38:53 2008 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Frysinger X-Patchwork-Id: 8496 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5F3E8DDD0B for ; Thu, 13 Nov 2008 10:40:13 +1100 (EST) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.68 #1 (Red Hat Linux)) id 1L0PIY-0006yw-HH; Wed, 12 Nov 2008 23:38:58 +0000 Received: from smtp.gentoo.org ([140.211.166.183]) by bombadil.infradead.org with esmtps (Exim 4.68 #1 (Red Hat Linux)) id 1L0PIV-0006uA-Mp for linux-mtd@lists.infradead.org; Wed, 12 Nov 2008 23:38:56 +0000 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id E478A64517; Wed, 12 Nov 2008 23:38:53 +0000 (UTC) From: Mike Frysinger To: linux-mtd@lists.infradead.org, David Woodhouse Subject: [PATCH] mtd: unify mtd partition/device registration Date: Wed, 12 Nov 2008 18:38:53 -0500 Message-Id: <1226533133-7405-1-git-send-email-vapier@gentoo.org> X-Mailer: git-send-email 1.6.0.3 X-Spam-Score: 0.4 (/) X-Spam-Report: SpamAssassin version 3.2.5 on bombadil.infradead.org summary: Content analysis details: (0.4 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.4 SUBJECT_FUZZY_TION Attempt to obfuscate words in Subject: Cc: linux-kernel@vger.kernel.org X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.9 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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 --- 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 + +/** + * 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);