aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/cmdlinepart.c
diff options
context:
space:
mode:
authorArtem Bityutskiy <artem.bityutskiy@linux.intel.com>2012-09-02 06:54:14 -0400
committerDavid Woodhouse <David.Woodhouse@intel.com>2012-09-29 10:33:00 -0400
commit9e0606fc4ea27fb275f6987751224c60ee055ef1 (patch)
tree284b1818429d0bc6c1299c31d6ddeebfe1e17194 /drivers/mtd/cmdlinepart.c
parent3cf7f1314ed88598b640318f60d8d5fb40509f23 (diff)
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>
Diffstat (limited to 'drivers/mtd/cmdlinepart.c')
-rw-r--r--drivers/mtd/cmdlinepart.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c
index b4faca25cf31..58dd0d0d7383 100644
--- a/drivers/mtd/cmdlinepart.c
+++ b/drivers/mtd/cmdlinepart.c
@@ -39,11 +39,10 @@
39 39
40#include <linux/kernel.h> 40#include <linux/kernel.h>
41#include <linux/slab.h> 41#include <linux/slab.h>
42
43#include <linux/mtd/mtd.h> 42#include <linux/mtd/mtd.h>
44#include <linux/mtd/partitions.h> 43#include <linux/mtd/partitions.h>
45#include <linux/bootmem.h>
46#include <linux/module.h> 44#include <linux/module.h>
45#include <linux/err.h>
47 46
48/* error message prefix */ 47/* error message prefix */
49#define ERRP "mtd: " 48#define ERRP "mtd: "
@@ -110,7 +109,7 @@ static struct mtd_partition * newpart(char *s,
110 if (size < PAGE_SIZE) 109 if (size < PAGE_SIZE)
111 { 110 {
112 printk(KERN_ERR ERRP "partition size too small (%lx)\n", size); 111 printk(KERN_ERR ERRP "partition size too small (%lx)\n", size);
113 return NULL; 112 return ERR_PTR(-EINVAL);
114 } 113 }
115 } 114 }
116 115
@@ -138,7 +137,7 @@ static struct mtd_partition * newpart(char *s,
138 if (!p) 137 if (!p)
139 { 138 {
140 printk(KERN_ERR ERRP "no closing %c found in partition name\n", delim); 139 printk(KERN_ERR ERRP "no closing %c found in partition name\n", delim);
141 return NULL; 140 return ERR_PTR(-EINVAL);
142 } 141 }
143 name_len = p - name; 142 name_len = p - name;
144 s = p + 1; 143 s = p + 1;
@@ -172,13 +171,13 @@ static struct mtd_partition * newpart(char *s,
172 if (size == SIZE_REMAINING) 171 if (size == SIZE_REMAINING)
173 { 172 {
174 printk(KERN_ERR ERRP "no partitions allowed after a fill-up partition\n"); 173 printk(KERN_ERR ERRP "no partitions allowed after a fill-up partition\n");
175 return NULL; 174 return ERR_PTR(-EINVAL);
176 } 175 }
177 /* more partitions follow, parse them */ 176 /* more partitions follow, parse them */
178 parts = newpart(s + 1, &s, num_parts, this_part + 1, 177 parts = newpart(s + 1, &s, num_parts, this_part + 1,
179 &extra_mem, extra_mem_size); 178 &extra_mem, extra_mem_size);
180 if (!parts) 179 if (IS_ERR(parts))
181 return NULL; 180 return parts;
182 } 181 }
183 else 182 else
184 { /* this is the last partition: allocate space for all */ 183 { /* this is the last partition: allocate space for all */
@@ -189,7 +188,7 @@ static struct mtd_partition * newpart(char *s,
189 extra_mem_size; 188 extra_mem_size;
190 parts = kzalloc(alloc_size, GFP_KERNEL); 189 parts = kzalloc(alloc_size, GFP_KERNEL);
191 if (!parts) 190 if (!parts)
192 return NULL; 191 return ERR_PTR(-ENOMEM);
193 extra_mem = (unsigned char *)(parts + *num_parts); 192 extra_mem = (unsigned char *)(parts + *num_parts);
194 } 193 }
195 /* enter this partition (offset will be calculated later if it is zero at this point) */ 194 /* 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)
245 if (!(p = strchr(s, ':'))) 244 if (!(p = strchr(s, ':')))
246 { 245 {
247 printk(KERN_ERR ERRP "no mtd-id\n"); 246 printk(KERN_ERR ERRP "no mtd-id\n");
248 return 0; 247 return -EINVAL;
249 } 248 }
250 mtd_id_len = p - mtd_id; 249 mtd_id_len = p - mtd_id;
251 250
@@ -262,7 +261,7 @@ static int mtdpart_setup_real(char *s)
262 (unsigned char**)&this_mtd, /* out: extra mem */ 261 (unsigned char**)&this_mtd, /* out: extra mem */
263 mtd_id_len + 1 + sizeof(*this_mtd) + 262 mtd_id_len + 1 + sizeof(*this_mtd) +
264 sizeof(void*)-1 /*alignment*/); 263 sizeof(void*)-1 /*alignment*/);
265 if(!parts) 264 if (IS_ERR(parts))
266 { 265 {
267 /* 266 /*
268 * An error occurred. We're either: 267 * An error occurred. We're either:
@@ -271,7 +270,7 @@ static int mtdpart_setup_real(char *s)
271 * Either way, this mtd is hosed and we're 270 * Either way, this mtd is hosed and we're
272 * unlikely to succeed in parsing any more 271 * unlikely to succeed in parsing any more
273 */ 272 */
274 return 0; 273 return PTR_ERR(parts);
275 } 274 }
276 275
277 /* align this_mtd */ 276 /* align this_mtd */
@@ -299,11 +298,11 @@ static int mtdpart_setup_real(char *s)
299 if (*s != ';') 298 if (*s != ';')
300 { 299 {
301 printk(KERN_ERR ERRP "bad character after partition (%c)\n", *s); 300 printk(KERN_ERR ERRP "bad character after partition (%c)\n", *s);
302 return 0; 301 return -EINVAL;
303 } 302 }
304 s++; 303 s++;
305 } 304 }
306 return 1; 305 return 0;
307} 306}
308 307
309/* 308/*
@@ -318,13 +317,16 @@ static int parse_cmdline_partitions(struct mtd_info *master,
318 struct mtd_part_parser_data *data) 317 struct mtd_part_parser_data *data)
319{ 318{
320 unsigned long offset; 319 unsigned long offset;
321 int i; 320 int i, err;
322 struct cmdline_mtd_partition *part; 321 struct cmdline_mtd_partition *part;
323 const char *mtd_id = master->name; 322 const char *mtd_id = master->name;
324 323
325 /* parse command line */ 324 /* parse command line */
326 if (!cmdline_parsed) 325 if (!cmdline_parsed) {
327 mtdpart_setup_real(cmdline); 326 err = mtdpart_setup_real(cmdline);
327 if (err)
328 return err;
329 }
328 330
329 for(part = partitions; part; part = part->next) 331 for(part = partitions; part; part = part->next)
330 { 332 {