forked from luck/tmp_suning_uos_patched
mtd: cmdlinepart: minor cleanups
Clean-up the driver a bit to make it easier to read and amend the coding style. Mostly these are changes like: if (a) { } => if (a) { } Some extra blank lines were added. Indentation was changed to use tabs instead of spaces. Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
This commit is contained in:
parent
9e0606fc4e
commit
fac0077cc0
@ -82,15 +82,14 @@ static int cmdline_parsed;
|
|||||||
* syntax has been verified ok.
|
* syntax has been verified ok.
|
||||||
*/
|
*/
|
||||||
static struct mtd_partition * newpart(char *s,
|
static struct mtd_partition * newpart(char *s,
|
||||||
char **retptr,
|
char **retptr,
|
||||||
int *num_parts,
|
int *num_parts,
|
||||||
int this_part,
|
int this_part,
|
||||||
unsigned char **extra_mem_ptr,
|
unsigned char **extra_mem_ptr,
|
||||||
int extra_mem_size)
|
int extra_mem_size)
|
||||||
{
|
{
|
||||||
struct mtd_partition *parts;
|
struct mtd_partition *parts;
|
||||||
unsigned long size;
|
unsigned long size, offset = OFFSET_CONTINUOUS;
|
||||||
unsigned long offset = OFFSET_CONTINUOUS;
|
|
||||||
char *name;
|
char *name;
|
||||||
int name_len;
|
int name_len;
|
||||||
unsigned char *extra_mem;
|
unsigned char *extra_mem;
|
||||||
@ -98,16 +97,13 @@ static struct mtd_partition * newpart(char *s,
|
|||||||
unsigned int mask_flags;
|
unsigned int mask_flags;
|
||||||
|
|
||||||
/* fetch the partition size */
|
/* fetch the partition size */
|
||||||
if (*s == '-')
|
if (*s == '-') {
|
||||||
{ /* assign all remaining space to this partition */
|
/* assign all remaining space to this partition */
|
||||||
size = SIZE_REMAINING;
|
size = SIZE_REMAINING;
|
||||||
s++;
|
s++;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
size = memparse(s, &s);
|
size = memparse(s, &s);
|
||||||
if (size < PAGE_SIZE)
|
if (size < PAGE_SIZE) {
|
||||||
{
|
|
||||||
printk(KERN_ERR ERRP "partition size too small (%lx)\n", size);
|
printk(KERN_ERR ERRP "partition size too small (%lx)\n", size);
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
}
|
}
|
||||||
@ -116,60 +112,51 @@ static struct mtd_partition * newpart(char *s,
|
|||||||
/* fetch partition name and flags */
|
/* fetch partition name and flags */
|
||||||
mask_flags = 0; /* this is going to be a regular partition */
|
mask_flags = 0; /* this is going to be a regular partition */
|
||||||
delim = 0;
|
delim = 0;
|
||||||
/* check for offset */
|
|
||||||
if (*s == '@')
|
/* check for offset */
|
||||||
{
|
if (*s == '@') {
|
||||||
s++;
|
s++;
|
||||||
offset = memparse(s, &s);
|
offset = memparse(s, &s);
|
||||||
}
|
|
||||||
/* now look for name */
|
|
||||||
if (*s == '(')
|
|
||||||
{
|
|
||||||
delim = ')';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (delim)
|
/* now look for name */
|
||||||
{
|
if (*s == '(')
|
||||||
|
delim = ')';
|
||||||
|
|
||||||
|
if (delim) {
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
name = ++s;
|
name = ++s;
|
||||||
p = strchr(name, delim);
|
p = strchr(name, delim);
|
||||||
if (!p)
|
if (!p) {
|
||||||
{
|
|
||||||
printk(KERN_ERR ERRP "no closing %c found in partition name\n", delim);
|
printk(KERN_ERR ERRP "no closing %c found in partition name\n", delim);
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
}
|
}
|
||||||
name_len = p - name;
|
name_len = p - name;
|
||||||
s = p + 1;
|
s = p + 1;
|
||||||
}
|
} else {
|
||||||
else
|
name = NULL;
|
||||||
{
|
|
||||||
name = NULL;
|
|
||||||
name_len = 13; /* Partition_000 */
|
name_len = 13; /* Partition_000 */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* record name length for memory allocation later */
|
/* record name length for memory allocation later */
|
||||||
extra_mem_size += name_len + 1;
|
extra_mem_size += name_len + 1;
|
||||||
|
|
||||||
/* test for options */
|
/* test for options */
|
||||||
if (strncmp(s, "ro", 2) == 0)
|
if (strncmp(s, "ro", 2) == 0) {
|
||||||
{
|
|
||||||
mask_flags |= MTD_WRITEABLE;
|
mask_flags |= MTD_WRITEABLE;
|
||||||
s += 2;
|
s += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if lk is found do NOT unlock the MTD partition*/
|
/* if lk is found do NOT unlock the MTD partition*/
|
||||||
if (strncmp(s, "lk", 2) == 0)
|
if (strncmp(s, "lk", 2) == 0) {
|
||||||
{
|
|
||||||
mask_flags |= MTD_POWERUP_LOCK;
|
mask_flags |= MTD_POWERUP_LOCK;
|
||||||
s += 2;
|
s += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* test if more partitions are following */
|
/* test if more partitions are following */
|
||||||
if (*s == ',')
|
if (*s == ',') {
|
||||||
{
|
if (size == SIZE_REMAINING) {
|
||||||
if (size == SIZE_REMAINING)
|
|
||||||
{
|
|
||||||
printk(KERN_ERR ERRP "no partitions allowed after a fill-up partition\n");
|
printk(KERN_ERR ERRP "no partitions allowed after a fill-up partition\n");
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
}
|
}
|
||||||
@ -178,44 +165,38 @@ static struct mtd_partition * newpart(char *s,
|
|||||||
&extra_mem, extra_mem_size);
|
&extra_mem, extra_mem_size);
|
||||||
if (IS_ERR(parts))
|
if (IS_ERR(parts))
|
||||||
return parts;
|
return parts;
|
||||||
}
|
} else {
|
||||||
else
|
/* this is the last partition: allocate space for all */
|
||||||
{ /* this is the last partition: allocate space for all */
|
|
||||||
int alloc_size;
|
int alloc_size;
|
||||||
|
|
||||||
*num_parts = this_part + 1;
|
*num_parts = this_part + 1;
|
||||||
alloc_size = *num_parts * sizeof(struct mtd_partition) +
|
alloc_size = *num_parts * sizeof(struct mtd_partition) +
|
||||||
extra_mem_size;
|
extra_mem_size;
|
||||||
|
|
||||||
parts = kzalloc(alloc_size, GFP_KERNEL);
|
parts = kzalloc(alloc_size, GFP_KERNEL);
|
||||||
if (!parts)
|
if (!parts)
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
extra_mem = (unsigned char *)(parts + *num_parts);
|
extra_mem = (unsigned char *)(parts + *num_parts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* enter this partition (offset will be calculated later if it is zero at this point) */
|
/* enter this partition (offset will be calculated later if it is zero at this point) */
|
||||||
parts[this_part].size = size;
|
parts[this_part].size = size;
|
||||||
parts[this_part].offset = offset;
|
parts[this_part].offset = offset;
|
||||||
parts[this_part].mask_flags = mask_flags;
|
parts[this_part].mask_flags = mask_flags;
|
||||||
if (name)
|
if (name)
|
||||||
{
|
|
||||||
strlcpy(extra_mem, name, name_len + 1);
|
strlcpy(extra_mem, name, name_len + 1);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
sprintf(extra_mem, "Partition_%03d", this_part);
|
sprintf(extra_mem, "Partition_%03d", this_part);
|
||||||
}
|
|
||||||
parts[this_part].name = extra_mem;
|
parts[this_part].name = extra_mem;
|
||||||
extra_mem += name_len + 1;
|
extra_mem += name_len + 1;
|
||||||
|
|
||||||
dbg(("partition %d: name <%s>, offset %llx, size %llx, mask flags %x\n",
|
dbg(("partition %d: name <%s>, offset %llx, size %llx, mask flags %x\n",
|
||||||
this_part,
|
this_part, parts[this_part].name, parts[this_part].offset,
|
||||||
parts[this_part].name,
|
parts[this_part].size, parts[this_part].mask_flags));
|
||||||
parts[this_part].offset,
|
|
||||||
parts[this_part].size,
|
|
||||||
parts[this_part].mask_flags));
|
|
||||||
|
|
||||||
/* return (updated) pointer to extra_mem memory */
|
/* return (updated) pointer to extra_mem memory */
|
||||||
if (extra_mem_ptr)
|
if (extra_mem_ptr)
|
||||||
*extra_mem_ptr = extra_mem;
|
*extra_mem_ptr = extra_mem;
|
||||||
|
|
||||||
/* return (updated) pointer command line string */
|
/* return (updated) pointer command line string */
|
||||||
*retptr = s;
|
*retptr = s;
|
||||||
@ -235,14 +216,14 @@ static int mtdpart_setup_real(char *s)
|
|||||||
{
|
{
|
||||||
struct cmdline_mtd_partition *this_mtd;
|
struct cmdline_mtd_partition *this_mtd;
|
||||||
struct mtd_partition *parts;
|
struct mtd_partition *parts;
|
||||||
int mtd_id_len;
|
int mtd_id_len, num_parts;
|
||||||
int num_parts;
|
|
||||||
char *p, *mtd_id;
|
char *p, *mtd_id;
|
||||||
|
|
||||||
mtd_id = s;
|
mtd_id = s;
|
||||||
|
|
||||||
/* fetch <mtd-id> */
|
/* fetch <mtd-id> */
|
||||||
if (!(p = strchr(s, ':')))
|
p = strchr(s, ':');
|
||||||
{
|
if (!p) {
|
||||||
printk(KERN_ERR ERRP "no mtd-id\n");
|
printk(KERN_ERR ERRP "no mtd-id\n");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
@ -261,8 +242,7 @@ static int mtdpart_setup_real(char *s)
|
|||||||
(unsigned char**)&this_mtd, /* out: extra mem */
|
(unsigned char**)&this_mtd, /* out: extra mem */
|
||||||
mtd_id_len + 1 + sizeof(*this_mtd) +
|
mtd_id_len + 1 + sizeof(*this_mtd) +
|
||||||
sizeof(void*)-1 /*alignment*/);
|
sizeof(void*)-1 /*alignment*/);
|
||||||
if (IS_ERR(parts))
|
if (IS_ERR(parts)) {
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
* An error occurred. We're either:
|
* An error occurred. We're either:
|
||||||
* a) out of memory, or
|
* a) out of memory, or
|
||||||
@ -275,7 +255,7 @@ static int mtdpart_setup_real(char *s)
|
|||||||
|
|
||||||
/* align this_mtd */
|
/* align this_mtd */
|
||||||
this_mtd = (struct cmdline_mtd_partition *)
|
this_mtd = (struct cmdline_mtd_partition *)
|
||||||
ALIGN((unsigned long)this_mtd, sizeof(void*));
|
ALIGN((unsigned long)this_mtd, sizeof(void *));
|
||||||
/* enter results */
|
/* enter results */
|
||||||
this_mtd->parts = parts;
|
this_mtd->parts = parts;
|
||||||
this_mtd->num_parts = num_parts;
|
this_mtd->num_parts = num_parts;
|
||||||
@ -295,13 +275,13 @@ static int mtdpart_setup_real(char *s)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
/* does another spec follow? */
|
/* does another spec follow? */
|
||||||
if (*s != ';')
|
if (*s != ';') {
|
||||||
{
|
|
||||||
printk(KERN_ERR ERRP "bad character after partition (%c)\n", *s);
|
printk(KERN_ERR ERRP "bad character after partition (%c)\n", *s);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,20 +308,18 @@ static int parse_cmdline_partitions(struct mtd_info *master,
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(part = partitions; part; part = part->next)
|
for (part = partitions; part; part = part->next) {
|
||||||
{
|
if ((!mtd_id) || (!strcmp(part->mtd_id, mtd_id))) {
|
||||||
if ((!mtd_id) || (!strcmp(part->mtd_id, mtd_id)))
|
for (i = 0, offset = 0; i < part->num_parts; i++) {
|
||||||
{
|
|
||||||
for(i = 0, offset = 0; i < part->num_parts; i++)
|
|
||||||
{
|
|
||||||
if (part->parts[i].offset == OFFSET_CONTINUOUS)
|
if (part->parts[i].offset == OFFSET_CONTINUOUS)
|
||||||
part->parts[i].offset = offset;
|
part->parts[i].offset = offset;
|
||||||
else
|
else
|
||||||
offset = part->parts[i].offset;
|
offset = part->parts[i].offset;
|
||||||
|
|
||||||
if (part->parts[i].size == SIZE_REMAINING)
|
if (part->parts[i].size == SIZE_REMAINING)
|
||||||
part->parts[i].size = master->size - offset;
|
part->parts[i].size = master->size - offset;
|
||||||
if (offset + part->parts[i].size > master->size)
|
|
||||||
{
|
if (offset + part->parts[i].size > master->size) {
|
||||||
printk(KERN_WARNING ERRP
|
printk(KERN_WARNING ERRP
|
||||||
"%s: partitioning exceeds flash size, truncating\n",
|
"%s: partitioning exceeds flash size, truncating\n",
|
||||||
part->mtd_id);
|
part->mtd_id);
|
||||||
@ -350,14 +328,17 @@ static int parse_cmdline_partitions(struct mtd_info *master,
|
|||||||
}
|
}
|
||||||
offset += part->parts[i].size;
|
offset += part->parts[i].size;
|
||||||
}
|
}
|
||||||
|
|
||||||
*pparts = kmemdup(part->parts,
|
*pparts = kmemdup(part->parts,
|
||||||
sizeof(*part->parts) * part->num_parts,
|
sizeof(*part->parts) * part->num_parts,
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
if (!*pparts)
|
if (!*pparts)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
return part->num_parts;
|
return part->num_parts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user