From patchwork Sat Aug 25 14:26:07 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huang Shijie X-Patchwork-Id: 179942 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 782622C00E7 for ; Sat, 25 Aug 2012 12:26:06 +1000 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T563Q-0003pk-TN; Sat, 25 Aug 2012 02:24:52 +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 1T563N-0003pU-J5 for linux-mtd@lists.infradead.org; Sat, 25 Aug 2012 02:24:50 +0000 Received: by pbbrq8 with SMTP id rq8so4582190pbb.36 for ; Fri, 24 Aug 2012 19:24:47 -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; bh=/md6DLm+OjawmeleA8cntTXe4Eno3ORhRoQpIR+wIRg=; b=oUqQnokXEK48KVtN/isRuKfW3u6YE2ZDf3P3OLqsYS/SKOsOwwL8yU9p/Fk3ghGg1Q EIKkT/9gIX1c1uC8kbnLxrTPzgO0cRtR2maNn2txmnNWuEOwxbp4f4UFg2dpns3foD9A Z4wcCWOO3SSemjjmT/Zyywd/vCJDz+Xo4ts3Z/CXfJnR1hBTvbHh+eG2TH52RYwtjBPa bA7MtrfhJIh53oQmZONDiZZa0sWSw7DraslsNzyZIH8HzoRz3UcTICa7NBsroDc0MUhC eGFq6FTbkwQJlMhViPz20F9Al5BaeXWHy8WqMeVPFPATq5kX6wh2EE7ol2JlqeuRornF xdLQ== Received: by 10.66.78.195 with SMTP id d3mr14723654pax.17.1345861487739; Fri, 24 Aug 2012 19:24:47 -0700 (PDT) Received: from localhost.localdomain.Home ([180.155.110.28]) by mx.google.com with ESMTPS id iu10sm9490236pbc.45.2012.08.24.19.24.43 (version=SSLv3 cipher=OTHER); Fri, 24 Aug 2012 19:24:46 -0700 (PDT) From: Huang Shijie To: dwmw2@infradead.org Subject: [PATCH v2] mtd: cmdlinepart: fix the wrong partitions number when truncating occurs Date: Sat, 25 Aug 2012 10:26:07 -0400 Message-Id: <1345904767-23011-1-git-send-email-shijie8@gmail.com> X-Mailer: git-send-email 1.7.4.4 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 , 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, and we set the partitions in the command line like this: #gpmi-nand:100m(boot),100m(kernel),1g(rootfs) In this case, the partition truncating occurs. The current code will get the following result: ---------------------------------- root@freescale ~$ cat /proc/mtd dev: size erasesize name mtd0: 06400000 00040000 "boot" mtd1: 06400000 00040000 "kernel" ---------------------------------- It is obvious that we lost the truncated partition `rootfs` which should be 824M in this case. Why? The old code sets the wrong partitions number when the truncating occurs. This patch fixes it. Alao add a `break` to shortcut the code in this case. After apply this patch, the result becomes: ---------------------------------- root@freescale ~$ cat /proc/mtd dev: size erasesize name mtd0: 06400000 00040000 "boot" mtd1: 06400000 00040000 "kernel" mtd2: 33800000 00040000 "rootfs" ---------------------------------- We get the right result. Signed-off-by: Huang Shijie --- v1 --> v2: [1] add more commit info. --- drivers/mtd/cmdlinepart.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c index 4558e0f..fc960a3 100644 --- a/drivers/mtd/cmdlinepart.c +++ b/drivers/mtd/cmdlinepart.c @@ -344,7 +344,8 @@ static int parse_cmdline_partitions(struct mtd_info *master, "%s: partitioning exceeds flash size, truncating\n", part->mtd_id); part->parts[i].size = master->size - offset; - part->num_parts = i; + part->num_parts = i + 1; + break; } offset += part->parts[i].size; }