From patchwork Tue Jun 7 15:48:58 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 99276 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 C86A5B6EE9 for ; Wed, 8 Jun 2011 01:49:22 +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 1QTyWc-0006ZB-Oa; Tue, 07 Jun 2011 15:49:02 +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 1QTyWc-0005nR-9M; Tue, 07 Jun 2011 15:49:02 +0000 Received: from mail-wy0-f177.google.com ([74.125.82.177]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QTyWZ-0005n8-6g for linux-mtd@lists.infradead.org; Tue, 07 Jun 2011 15:49:00 +0000 Received: by wyb28 with SMTP id 28so5036144wyb.36 for ; Tue, 07 Jun 2011 08:48:56 -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=vjMb3R747H6E8ht0dEkq8S8lh95aR8giqx50dVGSQuA=; b=f116bK5GsEFQF1q4vTF9rKTZAsTAVpChU3RCi3ih4r15YI9PySd2AomTxkzMuYp27Y 6XypuOh71i6/Qs4yDuT907QF6FTwqakvytIpnR6X30Ji8H2KA8Ghq+8+HiCZtwAgXX0/ CptMx43r6Nrn3o5Bqowr02BeI79QdwfDk9Gx4= 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=kiLIHhXr04RhGbfiplrVlY9wKoMZQqfyNbV7zMoTs5ZPq2A0rYmKSdWFkLij7r6Ot/ gwW261156nRy+7DWnrN7Tdqvlb59Kqnco4Zr9whq+HGS9H/Gdth/qMRHKkgewKnc4Yoe WnKwPrZnp1/c+H30d5dS2CzjsXyArbhA6CN3k= Received: by 10.216.142.133 with SMTP id i5mr6342121wej.43.1307461736744; Tue, 07 Jun 2011 08:48:56 -0700 (PDT) Received: from doriath.ww600.siemens.net ([91.213.169.4]) by mx.google.com with ESMTPS id z22sm2940891weq.2.2011.06.07.08.48.54 (version=SSLv3 cipher=OTHER); Tue, 07 Jun 2011 08:48:55 -0700 (PDT) From: Dmitry Eremin-Solenikov To: linux-mtd@lists.infradead.org Subject: [PATCH 01/44] mtd: add new API for handling MTD registration Date: Tue, 7 Jun 2011 19:48:58 +0400 Message-Id: <1307461738-16811-1-git-send-email-dbaryshkov@gmail.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <20110607134429.GE21174@pulham.picochip.com> References: <20110607134429.GE21174@pulham.picochip.com> X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110607_114859_529833_0AD10343 X-CRM114-Status: GOOD ( 18.78 ) 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.177 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: Jamie Iles , David Woodhouse , 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 | 47 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/mtd/mtd.h | 5 +++++ 2 files changed, 52 insertions(+), 0 deletions(-) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index c510aff..d538e0a 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -452,6 +452,53 @@ int mtd_device_register(struct mtd_info *master, EXPORT_SYMBOL_GPL(mtd_device_register); /** + * mtd_device_parse_register - register an MTD device. + * + * @mtd: the MTD device to register + * @part_probe_types: the list of MTD partition probes to try + * @origin: start address of MTD device. =0 unless you are sure you need this. + * @defparts: default partition information to register. Only valid if + * defnr_parts > 0 + * @defnr_parts: the number of partitions in defparts. If zero then the full + * MTD device is registered if no partition info is found + * + * Extract partition info and register MTD device (partitions or a whole device) + * It calls parse_mtd_partitions(), checks the result. If there were no + * partitions found, it uses default info specified (via defparts/defnr_parts) + * and then registers either partitions, or (if no partitions were + * found/specified) the whow MTD. + */ +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) +{ + int err; + struct mtd_partition *parts; + + err = parse_mtd_partitions(mtd, part_probe_types, &parts, origin); + if (err <= 0 && defnr_parts) { + parts = kmemdup(defparts, sizeof(*parts) * defnr_parts, + GFP_KERNEL); + if (!parts) + err = -ENOMEM; + } + + if (err > 0) { + err = add_mtd_partitions(mtd, parts, err); + kfree(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);