Skip to content

Commit 9e0606f

Browse files
dedekindDavid Woodhouse
authored andcommitted
mtd: cmdlinepart: revise error handling
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>
1 parent 3cf7f13 commit 9e0606f

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

drivers/mtd/cmdlinepart.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,10 @@
3939

4040
#include <linux/kernel.h>
4141
#include <linux/slab.h>
42-
4342
#include <linux/mtd/mtd.h>
4443
#include <linux/mtd/partitions.h>
45-
#include <linux/bootmem.h>
4644
#include <linux/module.h>
45+
#include <linux/err.h>
4746

4847
/* error message prefix */
4948
#define ERRP "mtd: "
@@ -110,7 +109,7 @@ static struct mtd_partition * newpart(char *s,
110109
if (size < PAGE_SIZE)
111110
{
112111
printk(KERN_ERR ERRP "partition size too small (%lx)\n", size);
113-
return NULL;
112+
return ERR_PTR(-EINVAL);
114113
}
115114
}
116115

@@ -138,7 +137,7 @@ static struct mtd_partition * newpart(char *s,
138137
if (!p)
139138
{
140139
printk(KERN_ERR ERRP "no closing %c found in partition name\n", delim);
141-
return NULL;
140+
return ERR_PTR(-EINVAL);
142141
}
143142
name_len = p - name;
144143
s = p + 1;
@@ -172,13 +171,13 @@ static struct mtd_partition * newpart(char *s,
172171
if (size == SIZE_REMAINING)
173172
{
174173
printk(KERN_ERR ERRP "no partitions allowed after a fill-up partition\n");
175-
return NULL;
174+
return ERR_PTR(-EINVAL);
176175
}
177176
/* more partitions follow, parse them */
178177
parts = newpart(s + 1, &s, num_parts, this_part + 1,
179178
&extra_mem, extra_mem_size);
180-
if (!parts)
181-
return NULL;
179+
if (IS_ERR(parts))
180+
return parts;
182181
}
183182
else
184183
{ /* this is the last partition: allocate space for all */
@@ -189,7 +188,7 @@ static struct mtd_partition * newpart(char *s,
189188
extra_mem_size;
190189
parts = kzalloc(alloc_size, GFP_KERNEL);
191190
if (!parts)
192-
return NULL;
191+
return ERR_PTR(-ENOMEM);
193192
extra_mem = (unsigned char *)(parts + *num_parts);
194193
}
195194
/* enter this partition (offset will be calculated later if it is zero at this point) */
@@ -245,7 +244,7 @@ static int mtdpart_setup_real(char *s)
245244
if (!(p = strchr(s, ':')))
246245
{
247246
printk(KERN_ERR ERRP "no mtd-id\n");
248-
return 0;
247+
return -EINVAL;
249248
}
250249
mtd_id_len = p - mtd_id;
251250

@@ -262,7 +261,7 @@ static int mtdpart_setup_real(char *s)
262261
(unsigned char**)&this_mtd, /* out: extra mem */
263262
mtd_id_len + 1 + sizeof(*this_mtd) +
264263
sizeof(void*)-1 /*alignment*/);
265-
if(!parts)
264+
if (IS_ERR(parts))
266265
{
267266
/*
268267
* An error occurred. We're either:
@@ -271,7 +270,7 @@ static int mtdpart_setup_real(char *s)
271270
* Either way, this mtd is hosed and we're
272271
* unlikely to succeed in parsing any more
273272
*/
274-
return 0;
273+
return PTR_ERR(parts);
275274
}
276275

277276
/* align this_mtd */
@@ -299,11 +298,11 @@ static int mtdpart_setup_real(char *s)
299298
if (*s != ';')
300299
{
301300
printk(KERN_ERR ERRP "bad character after partition (%c)\n", *s);
302-
return 0;
301+
return -EINVAL;
303302
}
304303
s++;
305304
}
306-
return 1;
305+
return 0;
307306
}
308307

309308
/*
@@ -318,13 +317,16 @@ static int parse_cmdline_partitions(struct mtd_info *master,
318317
struct mtd_part_parser_data *data)
319318
{
320319
unsigned long offset;
321-
int i;
320+
int i, err;
322321
struct cmdline_mtd_partition *part;
323322
const char *mtd_id = master->name;
324323

325324
/* parse command line */
326-
if (!cmdline_parsed)
327-
mtdpart_setup_real(cmdline);
325+
if (!cmdline_parsed) {
326+
err = mtdpart_setup_real(cmdline);
327+
if (err)
328+
return err;
329+
}
328330

329331
for(part = partitions; part; part = part->next)
330332
{

0 commit comments

Comments
 (0)