From patchwork Wed Jun 8 16:05:10 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 99459 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7C905B6FBC for ; Thu, 9 Jun 2011 02:06:34 +1000 (EST) Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QULGm-0007Jv-6u; Wed, 08 Jun 2011 16:06:12 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QULGl-0007GU-IF; Wed, 08 Jun 2011 16:06:11 +0000 Received: from mail-ww0-f49.google.com ([74.125.82.49]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QULGX-0007Bz-3U for linux-mtd@lists.infradead.org; Wed, 08 Jun 2011 16:05:58 +0000 Received: by wwb39 with SMTP id 39so531325wwb.18 for ; Wed, 08 Jun 2011 09:05:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=vsZis1WRSUe8euYyAhmvqQKOSHiSTPOs6P72fEmTe7U=; b=CVNc7Ymzl+CFdvyM2QoV5mRboHa72Cv/6CJasfsCRTaSDx8cua+jfAZa52Emvuikf0 JzRzQFv/GgvbRtvSewPOGpWl0Z/Nr3Xuv1p2kVmf8Ot0wqfZxUf2tN2XIhyUNQT+N+At /70AqD1+GJ35IHPbQgkjOrMm7VZU4mJaROsOI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=K/ujekebIO3ujw27Zrpm1Fs/U6zaZtcunp5cX0wo3/1NfUYkL+6gJpMSi8sMCGFleL PnEvC4fO8SbdYF/waiQxJVzlA8c3hpIZjffrZHegDcNU8fJFOOTl+rB7GX4a4xwO24If M2cxhW6kBoUjIhv42KPZPcFBwwGlGGKIhz48c= Received: by 10.227.11.137 with SMTP id t9mr12446wbt.9.1307549154609; Wed, 08 Jun 2011 09:05:54 -0700 (PDT) Received: from doriath.ww600.siemens.net ([91.213.169.4]) by mx.google.com with ESMTPS id p21sm526733wbh.6.2011.06.08.09.05.52 (version=SSLv3 cipher=OTHER); Wed, 08 Jun 2011 09:05:53 -0700 (PDT) From: Dmitry Eremin-Solenikov To: linux-mtd@lists.infradead.org Subject: [PATCH 01/43] mtd: add new API for handling MTD registration Date: Wed, 8 Jun 2011 20:05:10 +0400 Message-Id: <1307549152-7085-2-git-send-email-dbaryshkov@gmail.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1307549152-7085-1-git-send-email-dbaryshkov@gmail.com> References: <1307549152-7085-1-git-send-email-dbaryshkov@gmail.com> X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110608_120557_427438_ACAE2A42 X-CRM114-Status: GOOD ( 23.26 ) X-Spam-Score: -0.8 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-0.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.49 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is freemail (dbaryshkov[at]gmail.com) -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 RFC_ABUSE_POST Both abuse and postmaster missing on sender domain 0.0 T_TO_NO_BRKTS_FREEMAIL T_TO_NO_BRKTS_FREEMAIL Cc: David Woodhouse , Russell King , dedekind1@gmail.com X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 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 Lots (nearly all) mtd drivers contain nearly the similar code that calls parse_mtd_partitions, provides some platform-default values, if parsing fails, and registers mtd device. This is an aim to provide single implementation of this scenario: mtd_device_parse_register() which will handle all this parsing and defaults. Signed-off-by: Dmitry Eremin-Solenikov --- drivers/mtd/mtdcore.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/mtd/mtd.h | 5 ++++ 2 files changed, 65 insertions(+), 0 deletions(-) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index c510aff..a0b41e3 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -452,6 +452,66 @@ int mtd_device_register(struct mtd_info *master, EXPORT_SYMBOL_GPL(mtd_device_register); /** + * mtd_device_parse_register - parse partitions and register an MTD device. + * + * @mtd: the MTD device to register + * @types: the list of MTD partition probes to try, see + * 'parse_mtd_partitions()' for more information + * @origin: start address of MTD device, %0 unless you are sure you need this. + * @parts: fallback partition information to register, if parsing fails; + * only valid if %nr_parts > %0 + * @nr_parts: the number of partitions in parts, if zero then the full + * MTD device is registered if no partition info is found + * + * This function aggregates MTD partitions parsing (done by + * 'parse_mtd_partitions()') and MTD device and partitions registering. It + * basically follows the most common pattern found in many MTD drivers: + * + * * It first tries to probe partitions on MTD device @mtd using parsers + * specified in @types (if @types is %NULL, then the default list of + * parsers is used, see 'parse_mtd_partitions()' for more information). + * * If none are found this functions tries to fallback to information + * specified in @parts/@nr_parts. + * * If any parititioning info was found, this function registers + * the found partitions. + * * If no partitions were found this function just registers the MTD + * device @mtd and exits. + * + * Returns zero in case of success and a negative error code in case of + * failure. + */ +int mtd_device_parse_register(struct mtd_info *mtd, + const char **types, + unsigned long origin, + const struct mtd_partition *parts, + int nr_parts) +{ + int err; + struct mtd_partition *real_parts; + + err = parse_mtd_partitions(mtd, types, &real_parts, origin); + if (err <= 0 && nr_parts) { + real_parts = kmemdup(parts, sizeof(*parts) * nr_parts, + GFP_KERNEL); + err = nr_parts; + if (!parts) + err = -ENOMEM; + } + + if (err > 0) { + err = add_mtd_partitions(mtd, real_parts, err); + kfree(real_parts); + } else if (err == 0) { + err = add_mtd_device(mtd); + if (err == 1) + err = -ENODEV; + } + + return err; +} +EXPORT_SYMBOL_GPL(mtd_device_parse_register); + +/** * mtd_device_unregister - unregister an existing MTD device. * * @master: the MTD device to unregister. This will unregister both the master diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 2541fb8..d28a241 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -327,6 +327,11 @@ struct mtd_partition; extern int mtd_device_register(struct mtd_info *master, const struct mtd_partition *parts, int nr_parts); +extern int mtd_device_parse_register(struct mtd_info *mtd, + const char **part_probe_types, + unsigned long origin, + const struct mtd_partition *defparts, + int defnr_parts); extern int mtd_device_unregister(struct mtd_info *master); extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num); extern int __get_mtd_device(struct mtd_info *mtd);