diff options
author | Huang Shijie <shijie8@gmail.com> | 2012-08-18 13:07:41 -0400 |
---|---|---|
committer | David Woodhouse <David.Woodhouse@intel.com> | 2012-09-29 10:06:13 -0400 |
commit | c51803ddba10d80d9f246066802c6e359cf1d44c (patch) | |
tree | ed373709295c8213c7b7662f6e8526e48b574ca0 /drivers/mtd/mtdpart.c | |
parent | d0788ce4924758249c9552c91cc33024d3434419 (diff) |
mtd: mtdpart: break it as soon as we parse out the partitions
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 <shijie8@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Diffstat (limited to 'drivers/mtd/mtdpart.c')
-rw-r--r-- | 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 d518e4db8a0b..f8c08ec65feb 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c | |||
@@ -711,6 +711,8 @@ static const char *default_mtd_part_types[] = { | |||
711 | * partition parsers, specified in @types. However, if @types is %NULL, then | 711 | * partition parsers, specified in @types. However, if @types is %NULL, then |
712 | * the default list of parsers is used. The default list contains only the | 712 | * the default list of parsers is used. The default list contains only the |
713 | * "cmdlinepart" and "ofpart" parsers ATM. | 713 | * "cmdlinepart" and "ofpart" parsers ATM. |
714 | * Note: If there are more then one parser in @types, the kernel only takes the | ||
715 | * partitions parsed out by the first parser. | ||
714 | * | 716 | * |
715 | * This function may return: | 717 | * This function may return: |
716 | * o a negative error code in case of failure | 718 | * o a negative error code in case of failure |
@@ -735,11 +737,12 @@ int parse_mtd_partitions(struct mtd_info *master, const char **types, | |||
735 | if (!parser) | 737 | if (!parser) |
736 | continue; | 738 | continue; |
737 | ret = (*parser->parse_fn)(master, pparts, data); | 739 | ret = (*parser->parse_fn)(master, pparts, data); |
740 | put_partition_parser(parser); | ||
738 | if (ret > 0) { | 741 | if (ret > 0) { |
739 | printk(KERN_NOTICE "%d %s partitions found on MTD device %s\n", | 742 | printk(KERN_NOTICE "%d %s partitions found on MTD device %s\n", |
740 | ret, parser->name, master->name); | 743 | ret, parser->name, master->name); |
744 | break; | ||
741 | } | 745 | } |
742 | put_partition_parser(parser); | ||
743 | } | 746 | } |
744 | return ret; | 747 | return ret; |
745 | } | 748 | } |