From patchwork Sun Aug 26 17:21:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huang Shijie X-Patchwork-Id: 180025 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (unknown [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 582762C0109 for ; Sun, 26 Aug 2012 15:21:44 +1000 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T5VH5-0008IK-Ux; Sun, 26 Aug 2012 05:20:40 +0000 Received: from mail-pb0-f49.google.com ([209.85.160.49]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1T5VGy-0008Hc-4O for linux-mtd@lists.infradead.org; Sun, 26 Aug 2012 05:20:32 +0000 Received: by pbbrq8 with SMTP id rq8so5883036pbb.36 for ; Sat, 25 Aug 2012 22:20:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=BOuCeWjbvCkJVixeFLX1IUKfw/9OEYQnvyOETkjawmE=; b=IFsTl5yvtzznLRrqlBtduPf1kY8CmjxZ3jjTv5YbkXLD9VVjdYBE5NJW0RQVZkDejv woXIG8XZaRiOUo5rLYc7sQcNxEhN5TGa2Y3aYl3tLQEG7GeCkXeCPQUesQvOZ9Ex0RCB 6/d3z3+sHvPlafUKxetZvaveHUs7FE+X/2GRkXVM//0ghgDLVbrMEEQe+mtjSYFRwXTQ tToJHUnVSJR3Q8K82bUQnbJBCjWmdkerBtTdtd4IevTDe83GTK70Xt2kNcNDQASxaJtg ZIuTca3fht8iaKg673SKewQXl/bUPzc9E7G0aIEZ1I8fd4OIBBbGoaGrLSr/Wxnx56cr /wVg== Received: by 10.68.217.202 with SMTP id pa10mr25036185pbc.15.1345958431178; Sat, 25 Aug 2012 22:20:31 -0700 (PDT) Received: from localhost.localdomain.Home ([180.155.110.28]) by mx.google.com with ESMTPS id y11sm11843545pbv.66.2012.08.25.22.20.27 (version=SSLv3 cipher=OTHER); Sat, 25 Aug 2012 22:20:30 -0700 (PDT) From: Huang Shijie To: dwmw2@infradead.org Subject: [PATCH 2/3] mtd: cmdlinepart: sort the unsorted partitions Date: Sun, 26 Aug 2012 13:21:39 -0400 Message-Id: <1346001700-26895-2-git-send-email-shijie8@gmail.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1346001700-26895-1-git-send-email-shijie8@gmail.com> References: <1346001700-26895-1-git-send-email-shijie8@gmail.com> X-Spam-Note: CRM114 invocation failed X-Spam-Score: 0.7 (/) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.160.49 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (shijie8[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 3.2 DATE_IN_FUTURE_12_24 Date: is 12 to 24 hours after Received: date 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (shijie8[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -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 Cc: Huang Shijie , shmulik.ladkani@gmail.com, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, dedekind1@gmail.com X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 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 Assume we have a 1GB(8Gb) nand chip. It is legit if we set the partitions as the following: gpmi-nand:1g@200m(rootfs),100m@0(boot),100m@100m(kernel) But the current code can not parse out any partition with this cmdline. This patch sorts the unsorted partitions by the @offset. For there are maybe only several partitions, i use the simple Bubble sort algorithm. Signed-off-by: Huang Shijie --- drivers/mtd/cmdlinepart.c | 29 +++++++++++++++++++++++++++++ 1 files changed, 29 insertions(+), 0 deletions(-) diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c index 0b7b2ad..f40d390 100644 --- a/drivers/mtd/cmdlinepart.c +++ b/drivers/mtd/cmdlinepart.c @@ -234,6 +234,32 @@ static struct mtd_partition * newpart(char *s, return parts; } +/* There are only several partitions, so the Bubble sort is enough. */ +static inline void sort_partitons(struct mtd_partition *parts, int num_parts) +{ + int i, j; + + if (num_parts < 2) + return; + + if (parts[0].offset == OFFSET_CONTINUOUS) + return; + + /* sort by the offset */ + for (i = 0; i < num_parts - 1; i++) { + for (j = 1; j < num_parts - i; j++) { + if (parts[j - 1].offset > parts[j].offset) { + struct mtd_partition tmp; + + tmp = parts[j - 1]; + parts[j - 1] = parts[j]; + parts[j] = tmp; + } + } + } + return; +} + /* * Parse the command line. */ @@ -292,6 +318,9 @@ static int mtdpart_setup_real(char *s) this_mtd->mtd_id = (char*)(this_mtd + 1); strlcpy(this_mtd->mtd_id, mtd_id, mtd_id_len + 1); + /* sort the partitions */ + sort_partitons(parts, num_parts); + /* link into chain */ this_mtd->next = partitions; partitions = this_mtd;