[MTD] mtdpart: Make all partition parsers return allocated array
authorAtsushi Nemoto <anemo@mba.ocn.ne.jp>
Fri, 6 Mar 2009 11:01:08 +0000 (20:01 +0900)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Fri, 20 Mar 2009 18:55:17 +0000 (18:55 +0000)
Currently redboot and afx parser return allocated mtd_partition array
and cmdlinepart and ar7 return persistent array.

This patch make cmdlinepart and ar7 also return allocated array, so
that all users can free it regardless of parser type.

Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
drivers/mtd/ar7part.c
drivers/mtd/cmdlinepart.c

index ecf170b55c3245650c220e1cf7bb75606ade0e84..6697a1ec72d067ec07a42c15986740ea33169095 100644 (file)
@@ -44,8 +44,6 @@ struct ar7_bin_rec {
        unsigned int address;
 };
 
-static struct mtd_partition ar7_parts[AR7_PARTS];
-
 static int create_mtd_partitions(struct mtd_info *master,
                                 struct mtd_partition **pparts,
                                 unsigned long origin)
@@ -57,7 +55,11 @@ static int create_mtd_partitions(struct mtd_info *master,
        unsigned int root_offset = ROOT_OFFSET;
 
        int retries = 10;
+       struct mtd_partition *ar7_parts;
 
+       ar7_parts = kzalloc(sizeof(*ar7_parts) * AR7_PARTS, GFP_KERNEL);
+       if (!ar7_parts)
+               return -ENOMEM;
        ar7_parts[0].name = "loader";
        ar7_parts[0].offset = 0;
        ar7_parts[0].size = master->erasesize;
index 50a340388e742024945b6011490c760d0de4dcad..5011fa73f91886302135ea08904908c2c6f89461 100644 (file)
@@ -335,7 +335,11 @@ static int parse_cmdline_partitions(struct mtd_info *master,
                                }
                                offset += part->parts[i].size;
                        }
-                       *pparts = part->parts;
+                       *pparts = kmemdup(part->parts,
+                                       sizeof(*part->parts) * part->num_parts,
+                                       GFP_KERNEL);
+                       if (!*pparts)
+                               return -ENOMEM;
                        return part->num_parts;
                }
        }