This patch revises and fixes error handling in the command line mtd
partitions parser. Namely:
1. we ignored return code of 'mtdpart_setup_real()'.
2. instead of returning 0 for failure and 1 for success, teach
'mtdpart_setup_real()' to return real error codes.
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
-#include <linux/bootmem.h>
#include <linux/module.h>
#include <linux/module.h>
/* error message prefix */
#define ERRP "mtd: "
/* error message prefix */
#define ERRP "mtd: "
if (size < PAGE_SIZE)
{
printk(KERN_ERR ERRP "partition size too small (%lx)\n", size);
if (size < PAGE_SIZE)
{
printk(KERN_ERR ERRP "partition size too small (%lx)\n", size);
+ return ERR_PTR(-EINVAL);
if (!p)
{
printk(KERN_ERR ERRP "no closing %c found in partition name\n", delim);
if (!p)
{
printk(KERN_ERR ERRP "no closing %c found in partition name\n", delim);
+ return ERR_PTR(-EINVAL);
}
name_len = p - name;
s = p + 1;
}
name_len = p - name;
s = p + 1;
if (size == SIZE_REMAINING)
{
printk(KERN_ERR ERRP "no partitions allowed after a fill-up partition\n");
if (size == SIZE_REMAINING)
{
printk(KERN_ERR ERRP "no partitions allowed after a fill-up partition\n");
+ return ERR_PTR(-EINVAL);
}
/* more partitions follow, parse them */
parts = newpart(s + 1, &s, num_parts, this_part + 1,
&extra_mem, extra_mem_size);
}
/* more partitions follow, parse them */
parts = newpart(s + 1, &s, num_parts, this_part + 1,
&extra_mem, extra_mem_size);
- if (!parts)
- return NULL;
+ if (IS_ERR(parts))
+ return parts;
}
else
{ /* this is the last partition: allocate space for all */
}
else
{ /* this is the last partition: allocate space for all */
extra_mem_size;
parts = kzalloc(alloc_size, GFP_KERNEL);
if (!parts)
extra_mem_size;
parts = kzalloc(alloc_size, GFP_KERNEL);
if (!parts)
+ return ERR_PTR(-ENOMEM);
extra_mem = (unsigned char *)(parts + *num_parts);
}
/* enter this partition (offset will be calculated later if it is zero at this point) */
extra_mem = (unsigned char *)(parts + *num_parts);
}
/* enter this partition (offset will be calculated later if it is zero at this point) */
if (!(p = strchr(s, ':')))
{
printk(KERN_ERR ERRP "no mtd-id\n");
if (!(p = strchr(s, ':')))
{
printk(KERN_ERR ERRP "no mtd-id\n");
}
mtd_id_len = p - mtd_id;
}
mtd_id_len = p - mtd_id;
(unsigned char**)&this_mtd, /* out: extra mem */
mtd_id_len + 1 + sizeof(*this_mtd) +
sizeof(void*)-1 /*alignment*/);
(unsigned char**)&this_mtd, /* out: extra mem */
mtd_id_len + 1 + sizeof(*this_mtd) +
sizeof(void*)-1 /*alignment*/);
{
/*
* An error occurred. We're either:
{
/*
* An error occurred. We're either:
* Either way, this mtd is hosed and we're
* unlikely to succeed in parsing any more
*/
* Either way, this mtd is hosed and we're
* unlikely to succeed in parsing any more
*/
if (*s != ';')
{
printk(KERN_ERR ERRP "bad character after partition (%c)\n", *s);
if (*s != ';')
{
printk(KERN_ERR ERRP "bad character after partition (%c)\n", *s);
struct mtd_part_parser_data *data)
{
unsigned long offset;
struct mtd_part_parser_data *data)
{
unsigned long offset;
struct cmdline_mtd_partition *part;
const char *mtd_id = master->name;
/* parse command line */
struct cmdline_mtd_partition *part;
const char *mtd_id = master->name;
/* parse command line */
- if (!cmdline_parsed)
- mtdpart_setup_real(cmdline);
+ if (!cmdline_parsed) {
+ err = mtdpart_setup_real(cmdline);
+ if (err)
+ return err;
+ }
for(part = partitions; part; part = part->next)
{
for(part = partitions; part; part = part->next)
{