From patchwork Sat Aug 18 17:07:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huang Shijie X-Patchwork-Id: 178426 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 C2D4C2C008A for ; Sat, 18 Aug 2012 15:07:56 +1000 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T2bF8-0007ab-2c; Sat, 18 Aug 2012 05:06:38 +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 1T2bF4-0007aN-UJ for linux-mtd@lists.infradead.org; Sat, 18 Aug 2012 05:06:35 +0000 Received: by pbbrq8 with SMTP id rq8so4617306pbb.36 for ; Fri, 17 Aug 2012 22:06:33 -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=/yOGIr5Njep6F1hdxsa1LZyIzP8IoH6v/htm+MKA1b8=; b=YJilo7gOMX8IQLcLZen6p7qcARx/Z0WigUy7n/V+mbQBzwxwcWnLWbLp8D9sPgRyOd uwc+3nwvjc0Fa257/PqIdhgoAf1lWNKfJPWiXYIGYr6VyhVprZCw3EJRlGPOZ2oCTJNV AbXIzPlGdBvWakEFwExddXW+kAglUayT/E6Xv7ShhMo8EvjklsRGtdWecn1/RrjkkkI6 WWwgxlMdOd+wcLwWSfcuJPVeaFo3ZdjG0fMyekwD2bdNrAt/LC0CErHMQRFn2SA4x5qw xXojGQFpjLH0EZe/NDal4YUW6HE6VyNMV7iiCFB6RoMrJfCVkALqlst2fKTGgkGXhfcT qqvg== Received: by 10.68.231.130 with SMTP id tg2mr16893033pbc.70.1345266393329; Fri, 17 Aug 2012 22:06:33 -0700 (PDT) Received: from localhost.localdomain.Home ([180.155.110.28]) by mx.google.com with ESMTPS id rn4sm6333036pbb.51.2012.08.17.22.06.30 (version=SSLv3 cipher=OTHER); Fri, 17 Aug 2012 22:06:32 -0700 (PDT) From: Huang Shijie To: dwmw2@infradead.org Subject: [PATCH v2] mtd: mtdpart: break it as soon as we parse out the partitions Date: Sat, 18 Aug 2012 13:07:41 -0400 Message-Id: <1345309661-26165-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, 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 We may cause a memory leak when the @types has more then one parser. Take the `default_mtd_part_types` for example. The default_mtd_part_types has two parsers now: `cmdlinepart` and `ofpart`. Assume the following case: The kernel command line sets the partitions like: #gpmi-nand:20m(boot),20m(kernel),1g(rootfs),-(user) But the devicetree file(such as arch/arm/boot/dts/imx28-evk.dts) also sets the same partitions as the kernel command line does. In the current code, the partitions parsed out by the `ofpart` will overwrite the @pparts which has already set by the `cmdlinepart` parser, and the the partitions parsed out by the `cmdlinepart` is missed. A memory leak occurs. So we should break the code as soon as we parse out the partitions, In actually, this patch makes a priority order between the parsers. If one parser has already parsed out the partitions successfully, it's no need to use another parser anymore. Signed-off-by: Huang Shijie --- v1 --> v2: fix the wrong comment. --- drivers/mtd/mtdpart.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index d518e4d..f8c08ec 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -711,6 +711,8 @@ static const char *default_mtd_part_types[] = { * partition parsers, specified in @types. However, if @types is %NULL, then * the default list of parsers is used. The default list contains only the * "cmdlinepart" and "ofpart" parsers ATM. + * Note: If there are more then one parser in @types, the kernel only takes the + * partitions parsed out by the first parser. * * This function may return: * o a negative error code in case of failure @@ -735,11 +737,12 @@ int parse_mtd_partitions(struct mtd_info *master, const char **types, if (!parser) continue; ret = (*parser->parse_fn)(master, pparts, data); + put_partition_parser(parser); if (ret > 0) { printk(KERN_NOTICE "%d %s partitions found on MTD device %s\n", ret, parser->name, master->name); + break; } - put_partition_parser(parser); } return ret; }