netns xfrm: fix "ip xfrm state|policy count" misreport
[safe/jmp/linux-2.6] / drivers / mtd / cmdlinepart.c
index 6b8bb2e..1479da6 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: cmdlinepart.c,v 1.19 2005/11/07 11:14:19 gleixner Exp $
- *
  * Read flash partition table from command line
  *
  * Copyright 2002 SYSGO Real-Time Solutions GmbH
@@ -9,7 +7,8 @@
  *
  * mtdparts=<mtddef>[;<mtddef]
  * <mtddef>  := <mtd-id>:<partdef>[,<partdef>]
- * <partdef> := <size>[@offset][<name>][ro]
+ *              where <mtd-id> is the name from the "cat /proc/mtd" command
+ * <partdef> := <size>[@offset][<name>][ro][lk]
  * <mtd-id>  := unique name used in mapping driver/device (mtd->name)
  * <size>    := standard linux memsize OR "-" to denote all remaining space
  * <name>    := '(' NAME ')'
@@ -42,7 +41,8 @@
 
 
 /* special size referring to all the remaining space in a partition */
-#define SIZE_REMAINING 0xffffffff
+#define SIZE_REMAINING UINT_MAX
+#define OFFSET_CONTINUOUS UINT_MAX
 
 struct cmdline_mtd_partition {
        struct cmdline_mtd_partition *next;
@@ -75,7 +75,7 @@ static struct mtd_partition * newpart(char *s,
 {
        struct mtd_partition *parts;
        unsigned long size;
-       unsigned long offset = 0;
+       unsigned long offset = OFFSET_CONTINUOUS;
        char *name;
        int name_len;
        unsigned char *extra_mem;
@@ -118,7 +118,8 @@ static struct mtd_partition * newpart(char *s,
                char *p;
 
                name = ++s;
-               if ((p = strchr(name, delim)) == 0)
+               p = strchr(name, delim);
+               if (!p)
                {
                        printk(KERN_ERR ERRP "no closing %c found in partition name\n", delim);
                        return NULL;
@@ -142,6 +143,13 @@ static struct mtd_partition * newpart(char *s,
                s += 2;
         }
 
+        /* if lk is found do NOT unlock the MTD partition*/
+        if (strncmp(s, "lk", 2) == 0)
+       {
+               mask_flags |= MTD_POWERUP_LOCK;
+               s += 2;
+        }
+
        /* test if more partitions are following */
        if (*s == ',')
        {
@@ -151,9 +159,10 @@ static struct mtd_partition * newpart(char *s,
                        return NULL;
                }
                /* more partitions follow, parse them */
-               if ((parts = newpart(s + 1, &s, num_parts,
-                                    this_part + 1, &extra_mem, extra_mem_size)) == 0)
-                 return NULL;
+               parts = newpart(s + 1, &s, num_parts, this_part + 1,
+                               &extra_mem, extra_mem_size);
+               if (!parts)
+                       return NULL;
        }
        else
        {       /* this is the last partition: allocate space for all */
@@ -162,13 +171,12 @@ static struct mtd_partition * newpart(char *s,
                *num_parts = this_part + 1;
                alloc_size = *num_parts * sizeof(struct mtd_partition) +
                             extra_mem_size;
-               parts = kmalloc(alloc_size, GFP_KERNEL);
+               parts = kzalloc(alloc_size, GFP_KERNEL);
                if (!parts)
                {
                        printk(KERN_ERR ERRP "out of memory\n");
                        return NULL;
                }
-               memset(parts, 0, alloc_size);
                extra_mem = (unsigned char *)(parts + *num_parts);
        }
        /* enter this partition (offset will be calculated later if it is zero at this point) */
@@ -186,7 +194,7 @@ static struct mtd_partition * newpart(char *s,
        parts[this_part].name = extra_mem;
        extra_mem += name_len + 1;
 
-       dbg(("partition %d: name <%s>, offset %x, size %x, mask flags %x\n",
+       dbg(("partition %d: name <%s>, offset %llx, size %llx, mask flags %x\n",
             this_part,
             parts[this_part].name,
             parts[this_part].offset,
@@ -299,10 +307,7 @@ static int parse_cmdline_partitions(struct mtd_info *master,
        unsigned long offset;
        int i;
        struct cmdline_mtd_partition *part;
-       char *mtd_id = master->name;
-
-       if(!cmdline)
-               return -EINVAL;
+       const char *mtd_id = master->name;
 
        /* parse command line */
        if (!cmdline_parsed)
@@ -314,7 +319,7 @@ static int parse_cmdline_partitions(struct mtd_info *master,
                {
                        for(i = 0, offset = 0; i < part->num_parts; i++)
                        {
-                               if (!part->parts[i].offset)
+                               if (part->parts[i].offset == OFFSET_CONTINUOUS)
                                  part->parts[i].offset = offset;
                                else
                                  offset = part->parts[i].offset;
@@ -330,11 +335,15 @@ 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;
                }
        }
-       return -EINVAL;
+       return 0;
 }
 
 
@@ -345,7 +354,7 @@ static int parse_cmdline_partitions(struct mtd_info *master,
  *
  * This function needs to be visible for bootloaders.
  */
-int mtdpart_setup(char *s)
+static int mtdpart_setup(char *s)
 {
        cmdline = s;
        return 1;