@@ -82,32 +82,28 @@ static int cmdline_parsed;
8282 * syntax has been verified ok.
8383 */
8484static struct mtd_partition * newpart (char * s ,
85- char * * retptr ,
86- int * num_parts ,
87- int this_part ,
88- unsigned char * * extra_mem_ptr ,
89- int extra_mem_size )
85+ char * * retptr ,
86+ int * num_parts ,
87+ int this_part ,
88+ unsigned char * * extra_mem_ptr ,
89+ int extra_mem_size )
9090{
9191 struct mtd_partition * parts ;
92- unsigned long size ;
93- unsigned long offset = OFFSET_CONTINUOUS ;
92+ unsigned long size , offset = OFFSET_CONTINUOUS ;
9493 char * name ;
9594 int name_len ;
9695 unsigned char * extra_mem ;
9796 char delim ;
9897 unsigned int mask_flags ;
9998
10099 /* fetch the partition size */
101- if (* s == '-' )
102- { /* assign all remaining space to this partition */
100+ if (* s == '-' ) {
101+ /* assign all remaining space to this partition */
103102 size = SIZE_REMAINING ;
104103 s ++ ;
105- }
106- else
107- {
104+ } else {
108105 size = memparse (s , & s );
109- if (size < PAGE_SIZE )
110- {
106+ if (size < PAGE_SIZE ) {
111107 printk (KERN_ERR ERRP "partition size too small (%lx)\n" , size );
112108 return ERR_PTR (- EINVAL );
113109 }
@@ -116,60 +112,51 @@ static struct mtd_partition * newpart(char *s,
116112 /* fetch partition name and flags */
117113 mask_flags = 0 ; /* this is going to be a regular partition */
118114 delim = 0 ;
119- /* check for offset */
120- if (* s == '@' )
121- {
122- s ++ ;
123- offset = memparse (s , & s );
124- }
125- /* now look for name */
115+
116+ /* check for offset */
117+ if (* s == '@' ) {
118+ s ++ ;
119+ offset = memparse (s , & s );
120+ }
121+
122+ /* now look for name */
126123 if (* s == '(' )
127- {
128124 delim = ')' ;
129- }
130125
131- if (delim )
132- {
126+ if (delim ) {
133127 char * p ;
134128
135- name = ++ s ;
129+ name = ++ s ;
136130 p = strchr (name , delim );
137- if (!p )
138- {
131+ if (!p ) {
139132 printk (KERN_ERR ERRP "no closing %c found in partition name\n" , delim );
140133 return ERR_PTR (- EINVAL );
141134 }
142135 name_len = p - name ;
143136 s = p + 1 ;
144- }
145- else
146- {
147- name = NULL ;
137+ } else {
138+ name = NULL ;
148139 name_len = 13 ; /* Partition_000 */
149140 }
150141
151142 /* record name length for memory allocation later */
152143 extra_mem_size += name_len + 1 ;
153144
154- /* test for options */
155- if (strncmp (s , "ro" , 2 ) == 0 )
156- {
145+ /* test for options */
146+ if (strncmp (s , "ro" , 2 ) == 0 ) {
157147 mask_flags |= MTD_WRITEABLE ;
158148 s += 2 ;
159- }
149+ }
160150
161- /* if lk is found do NOT unlock the MTD partition*/
162- if (strncmp (s , "lk" , 2 ) == 0 )
163- {
151+ /* if lk is found do NOT unlock the MTD partition*/
152+ if (strncmp (s , "lk" , 2 ) == 0 ) {
164153 mask_flags |= MTD_POWERUP_LOCK ;
165154 s += 2 ;
166- }
155+ }
167156
168157 /* test if more partitions are following */
169- if (* s == ',' )
170- {
171- if (size == SIZE_REMAINING )
172- {
158+ if (* s == ',' ) {
159+ if (size == SIZE_REMAINING ) {
173160 printk (KERN_ERR ERRP "no partitions allowed after a fill-up partition\n" );
174161 return ERR_PTR (- EINVAL );
175162 }
@@ -178,44 +165,38 @@ static struct mtd_partition * newpart(char *s,
178165 & extra_mem , extra_mem_size );
179166 if (IS_ERR (parts ))
180167 return parts ;
181- }
182- else
183- { /* this is the last partition: allocate space for all */
168+ } else {
169+ /* this is the last partition: allocate space for all */
184170 int alloc_size ;
185171
186172 * num_parts = this_part + 1 ;
187173 alloc_size = * num_parts * sizeof (struct mtd_partition ) +
188174 extra_mem_size ;
175+
189176 parts = kzalloc (alloc_size , GFP_KERNEL );
190177 if (!parts )
191178 return ERR_PTR (- ENOMEM );
192179 extra_mem = (unsigned char * )(parts + * num_parts );
193180 }
181+
194182 /* enter this partition (offset will be calculated later if it is zero at this point) */
195183 parts [this_part ].size = size ;
196184 parts [this_part ].offset = offset ;
197185 parts [this_part ].mask_flags = mask_flags ;
198186 if (name )
199- {
200187 strlcpy (extra_mem , name , name_len + 1 );
201- }
202188 else
203- {
204189 sprintf (extra_mem , "Partition_%03d" , this_part );
205- }
206190 parts [this_part ].name = extra_mem ;
207191 extra_mem += name_len + 1 ;
208192
209193 dbg (("partition %d: name <%s>, offset %llx, size %llx, mask flags %x\n" ,
210- this_part ,
211- parts [this_part ].name ,
212- parts [this_part ].offset ,
213- parts [this_part ].size ,
214- parts [this_part ].mask_flags ));
194+ this_part , parts [this_part ].name , parts [this_part ].offset ,
195+ parts [this_part ].size , parts [this_part ].mask_flags ));
215196
216197 /* return (updated) pointer to extra_mem memory */
217198 if (extra_mem_ptr )
218- * extra_mem_ptr = extra_mem ;
199+ * extra_mem_ptr = extra_mem ;
219200
220201 /* return (updated) pointer command line string */
221202 * retptr = s ;
@@ -235,14 +216,14 @@ static int mtdpart_setup_real(char *s)
235216 {
236217 struct cmdline_mtd_partition * this_mtd ;
237218 struct mtd_partition * parts ;
238- int mtd_id_len ;
239- int num_parts ;
219+ int mtd_id_len , num_parts ;
240220 char * p , * mtd_id ;
241221
242- mtd_id = s ;
222+ mtd_id = s ;
223+
243224 /* fetch <mtd-id> */
244- if (!( p = strchr (s , ':' )))
245- {
225+ p = strchr (s , ':' );
226+ if (! p ) {
246227 printk (KERN_ERR ERRP "no mtd-id\n" );
247228 return - EINVAL ;
248229 }
@@ -261,8 +242,7 @@ static int mtdpart_setup_real(char *s)
261242 (unsigned char * * )& this_mtd , /* out: extra mem */
262243 mtd_id_len + 1 + sizeof (* this_mtd ) +
263244 sizeof (void * )-1 /*alignment*/ );
264- if (IS_ERR (parts ))
265- {
245+ if (IS_ERR (parts )) {
266246 /*
267247 * An error occurred. We're either:
268248 * a) out of memory, or
@@ -275,7 +255,7 @@ static int mtdpart_setup_real(char *s)
275255
276256 /* align this_mtd */
277257 this_mtd = (struct cmdline_mtd_partition * )
278- ALIGN ((unsigned long )this_mtd , sizeof (void * ));
258+ ALIGN ((unsigned long )this_mtd , sizeof (void * ));
279259 /* enter results */
280260 this_mtd -> parts = parts ;
281261 this_mtd -> num_parts = num_parts ;
@@ -295,13 +275,13 @@ static int mtdpart_setup_real(char *s)
295275 break ;
296276
297277 /* does another spec follow? */
298- if (* s != ';' )
299- {
278+ if (* s != ';' ) {
300279 printk (KERN_ERR ERRP "bad character after partition (%c)\n" , * s );
301280 return - EINVAL ;
302281 }
303282 s ++ ;
304283 }
284+
305285 return 0 ;
306286}
307287
@@ -328,20 +308,18 @@ static int parse_cmdline_partitions(struct mtd_info *master,
328308 return err ;
329309 }
330310
331- for (part = partitions ; part ; part = part -> next )
332- {
333- if ((!mtd_id ) || (!strcmp (part -> mtd_id , mtd_id )))
334- {
335- for (i = 0 , offset = 0 ; i < part -> num_parts ; i ++ )
336- {
311+ for (part = partitions ; part ; part = part -> next ) {
312+ if ((!mtd_id ) || (!strcmp (part -> mtd_id , mtd_id ))) {
313+ for (i = 0 , offset = 0 ; i < part -> num_parts ; i ++ ) {
337314 if (part -> parts [i ].offset == OFFSET_CONTINUOUS )
338- part -> parts [i ].offset = offset ;
315+ part -> parts [i ].offset = offset ;
339316 else
340- offset = part -> parts [i ].offset ;
317+ offset = part -> parts [i ].offset ;
318+
341319 if (part -> parts [i ].size == SIZE_REMAINING )
342- part -> parts [i ].size = master -> size - offset ;
343- if ( offset + part -> parts [ i ]. size > master -> size )
344- {
320+ part -> parts [i ].size = master -> size - offset ;
321+
322+ if ( offset + part -> parts [ i ]. size > master -> size ) {
345323 printk (KERN_WARNING ERRP
346324 "%s: partitioning exceeds flash size, truncating\n" ,
347325 part -> mtd_id );
@@ -350,14 +328,17 @@ static int parse_cmdline_partitions(struct mtd_info *master,
350328 }
351329 offset += part -> parts [i ].size ;
352330 }
331+
353332 * pparts = kmemdup (part -> parts ,
354333 sizeof (* part -> parts ) * part -> num_parts ,
355334 GFP_KERNEL );
356335 if (!* pparts )
357336 return - ENOMEM ;
337+
358338 return part -> num_parts ;
359339 }
360340 }
341+
361342 return 0 ;
362343}
363344
0 commit comments