39
39
40
40
#include <linux/kernel.h>
41
41
#include <linux/slab.h>
42
-
43
42
#include <linux/mtd/mtd.h>
44
43
#include <linux/mtd/partitions.h>
45
- #include <linux/bootmem.h>
46
44
#include <linux/module.h>
45
+ #include <linux/err.h>
47
46
48
47
/* error message prefix */
49
48
#define ERRP "mtd: "
@@ -110,7 +109,7 @@ static struct mtd_partition * newpart(char *s,
110
109
if (size < PAGE_SIZE )
111
110
{
112
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
137
if (!p )
139
138
{
140
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
142
name_len = p - name ;
144
143
s = p + 1 ;
@@ -172,13 +171,13 @@ static struct mtd_partition * newpart(char *s,
172
171
if (size == SIZE_REMAINING )
173
172
{
174
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
176
/* more partitions follow, parse them */
178
177
parts = newpart (s + 1 , & s , num_parts , this_part + 1 ,
179
178
& extra_mem , extra_mem_size );
180
- if (! parts )
181
- return NULL ;
179
+ if (IS_ERR ( parts ) )
180
+ return parts ;
182
181
}
183
182
else
184
183
{ /* this is the last partition: allocate space for all */
@@ -189,7 +188,7 @@ static struct mtd_partition * newpart(char *s,
189
188
extra_mem_size ;
190
189
parts = kzalloc (alloc_size , GFP_KERNEL );
191
190
if (!parts )
192
- return NULL ;
191
+ return ERR_PTR ( - ENOMEM ) ;
193
192
extra_mem = (unsigned char * )(parts + * num_parts );
194
193
}
195
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
244
if (!(p = strchr (s , ':' )))
246
245
{
247
246
printk (KERN_ERR ERRP "no mtd-id\n" );
248
- return 0 ;
247
+ return - EINVAL ;
249
248
}
250
249
mtd_id_len = p - mtd_id ;
251
250
@@ -262,7 +261,7 @@ static int mtdpart_setup_real(char *s)
262
261
(unsigned char * * )& this_mtd , /* out: extra mem */
263
262
mtd_id_len + 1 + sizeof (* this_mtd ) +
264
263
sizeof (void * )-1 /*alignment*/ );
265
- if (! parts )
264
+ if ( IS_ERR ( parts ) )
266
265
{
267
266
/*
268
267
* An error occurred. We're either:
@@ -271,7 +270,7 @@ static int mtdpart_setup_real(char *s)
271
270
* Either way, this mtd is hosed and we're
272
271
* unlikely to succeed in parsing any more
273
272
*/
274
- return 0 ;
273
+ return PTR_ERR ( parts ) ;
275
274
}
276
275
277
276
/* align this_mtd */
@@ -299,11 +298,11 @@ static int mtdpart_setup_real(char *s)
299
298
if (* s != ';' )
300
299
{
301
300
printk (KERN_ERR ERRP "bad character after partition (%c)\n" , * s );
302
- return 0 ;
301
+ return - EINVAL ;
303
302
}
304
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
317
struct mtd_part_parser_data * data )
319
318
{
320
319
unsigned long offset ;
321
- int i ;
320
+ int i , err ;
322
321
struct cmdline_mtd_partition * part ;
323
322
const char * mtd_id = master -> name ;
324
323
325
324
/* 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
+ }
328
330
329
331
for (part = partitions ; part ; part = part -> next )
330
332
{
0 commit comments