Commit fac0077cc0a1760f0afbac6526f56656ee025a34

Authored by Artem Bityutskiy
Committed by David Woodhouse
1 parent 9e0606fc4e

mtd: cmdlinepart: minor cleanups

Clean-up the driver a bit to make it easier to read and amend the coding style.
Mostly these are changes like:

if (a)
{
}

=>

if (a) {
}

Some extra blank lines were added.
Indentation was changed to use tabs instead of spaces.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>

Showing 1 changed file with 59 additions and 78 deletions Side-by-side Diff

drivers/mtd/cmdlinepart.c
... ... @@ -82,15 +82,14 @@
82 82 * syntax has been verified ok.
83 83 */
84 84 static 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)
90 90 {
91 91 struct mtd_partition *parts;
92   - unsigned long size;
93   - unsigned long offset = OFFSET_CONTINUOUS;
  92 + unsigned long size, offset = OFFSET_CONTINUOUS;
94 93 char *name;
95 94 int name_len;
96 95 unsigned char *extra_mem;
97 96  
98 97  
... ... @@ -98,16 +97,13 @@
98 97 unsigned int mask_flags;
99 98  
100 99 /* 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 */
103 102 size = SIZE_REMAINING;
104 103 s++;
105   - }
106   - else
107   - {
  104 + } else {
108 105 size = memparse(s, &s);
109   - if (size < PAGE_SIZE)
110   - {
  106 + if (size < PAGE_SIZE) {
111 107 printk(KERN_ERR ERRP "partition size too small (%lx)\n", size);
112 108 return ERR_PTR(-EINVAL);
113 109 }
114 110  
115 111  
116 112  
117 113  
118 114  
119 115  
120 116  
121 117  
122 118  
123 119  
124 120  
... ... @@ -116,60 +112,51 @@
116 112 /* fetch partition name and flags */
117 113 mask_flags = 0; /* this is going to be a regular partition */
118 114 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 */
126 123 if (*s == '(')
127   - {
128 124 delim = ')';
129   - }
130 125  
131   - if (delim)
132   - {
  126 + if (delim) {
133 127 char *p;
134 128  
135   - name = ++s;
  129 + name = ++s;
136 130 p = strchr(name, delim);
137   - if (!p)
138   - {
  131 + if (!p) {
139 132 printk(KERN_ERR ERRP "no closing %c found in partition name\n", delim);
140 133 return ERR_PTR(-EINVAL);
141 134 }
142 135 name_len = p - name;
143 136 s = p + 1;
144   - }
145   - else
146   - {
147   - name = NULL;
  137 + } else {
  138 + name = NULL;
148 139 name_len = 13; /* Partition_000 */
149 140 }
150 141  
151 142 /* record name length for memory allocation later */
152 143 extra_mem_size += name_len + 1;
153 144  
154   - /* test for options */
155   - if (strncmp(s, "ro", 2) == 0)
156   - {
  145 + /* test for options */
  146 + if (strncmp(s, "ro", 2) == 0) {
157 147 mask_flags |= MTD_WRITEABLE;
158 148 s += 2;
159   - }
  149 + }
160 150  
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) {
164 153 mask_flags |= MTD_POWERUP_LOCK;
165 154 s += 2;
166   - }
  155 + }
167 156  
168 157 /* test if more partitions are following */
169   - if (*s == ',')
170   - {
171   - if (size == SIZE_REMAINING)
172   - {
  158 + if (*s == ',') {
  159 + if (size == SIZE_REMAINING) {
173 160 printk(KERN_ERR ERRP "no partitions allowed after a fill-up partition\n");
174 161 return ERR_PTR(-EINVAL);
175 162 }
176 163  
177 164  
178 165  
179 166  
180 167  
181 168  
182 169  
183 170  
... ... @@ -178,44 +165,38 @@
178 165 &extra_mem, extra_mem_size);
179 166 if (IS_ERR(parts))
180 167 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 */
184 170 int alloc_size;
185 171  
186 172 *num_parts = this_part + 1;
187 173 alloc_size = *num_parts * sizeof(struct mtd_partition) +
188 174 extra_mem_size;
  175 +
189 176 parts = kzalloc(alloc_size, GFP_KERNEL);
190 177 if (!parts)
191 178 return ERR_PTR(-ENOMEM);
192 179 extra_mem = (unsigned char *)(parts + *num_parts);
193 180 }
  181 +
194 182 /* enter this partition (offset will be calculated later if it is zero at this point) */
195 183 parts[this_part].size = size;
196 184 parts[this_part].offset = offset;
197 185 parts[this_part].mask_flags = mask_flags;
198 186 if (name)
199   - {
200 187 strlcpy(extra_mem, name, name_len + 1);
201   - }
202 188 else
203   - {
204 189 sprintf(extra_mem, "Partition_%03d", this_part);
205   - }
206 190 parts[this_part].name = extra_mem;
207 191 extra_mem += name_len + 1;
208 192  
209 193 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));
215 196  
216 197 /* return (updated) pointer to extra_mem memory */
217 198 if (extra_mem_ptr)
218   - *extra_mem_ptr = extra_mem;
  199 + *extra_mem_ptr = extra_mem;
219 200  
220 201 /* return (updated) pointer command line string */
221 202 *retptr = s;
222 203  
223 204  
... ... @@ -235,14 +216,14 @@
235 216 {
236 217 struct cmdline_mtd_partition *this_mtd;
237 218 struct mtd_partition *parts;
238   - int mtd_id_len;
239   - int num_parts;
  219 + int mtd_id_len, num_parts;
240 220 char *p, *mtd_id;
241 221  
242   - mtd_id = s;
  222 + mtd_id = s;
  223 +
243 224 /* fetch <mtd-id> */
244   - if (!(p = strchr(s, ':')))
245   - {
  225 + p = strchr(s, ':');
  226 + if (!p) {
246 227 printk(KERN_ERR ERRP "no mtd-id\n");
247 228 return -EINVAL;
248 229 }
... ... @@ -261,8 +242,7 @@
261 242 (unsigned char**)&this_mtd, /* out: extra mem */
262 243 mtd_id_len + 1 + sizeof(*this_mtd) +
263 244 sizeof(void*)-1 /*alignment*/);
264   - if (IS_ERR(parts))
265   - {
  245 + if (IS_ERR(parts)) {
266 246 /*
267 247 * An error occurred. We're either:
268 248 * a) out of memory, or
... ... @@ -275,7 +255,7 @@
275 255  
276 256 /* align this_mtd */
277 257 this_mtd = (struct cmdline_mtd_partition *)
278   - ALIGN((unsigned long)this_mtd, sizeof(void*));
  258 + ALIGN((unsigned long)this_mtd, sizeof(void *));
279 259 /* enter results */
280 260 this_mtd->parts = parts;
281 261 this_mtd->num_parts = num_parts;
282 262  
... ... @@ -295,13 +275,13 @@
295 275 break;
296 276  
297 277 /* does another spec follow? */
298   - if (*s != ';')
299   - {
  278 + if (*s != ';') {
300 279 printk(KERN_ERR ERRP "bad character after partition (%c)\n", *s);
301 280 return -EINVAL;
302 281 }
303 282 s++;
304 283 }
  284 +
305 285 return 0;
306 286 }
307 287  
308 288  
309 289  
310 290  
... ... @@ -328,20 +308,18 @@
328 308 return err;
329 309 }
330 310  
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++) {
337 314 if (part->parts[i].offset == OFFSET_CONTINUOUS)
338   - part->parts[i].offset = offset;
  315 + part->parts[i].offset = offset;
339 316 else
340   - offset = part->parts[i].offset;
  317 + offset = part->parts[i].offset;
  318 +
341 319 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) {
345 323 printk(KERN_WARNING ERRP
346 324 "%s: partitioning exceeds flash size, truncating\n",
347 325 part->mtd_id);
348 326  
349 327  
... ... @@ -350,14 +328,17 @@
350 328 }
351 329 offset += part->parts[i].size;
352 330 }
  331 +
353 332 *pparts = kmemdup(part->parts,
354 333 sizeof(*part->parts) * part->num_parts,
355 334 GFP_KERNEL);
356 335 if (!*pparts)
357 336 return -ENOMEM;
  337 +
358 338 return part->num_parts;
359 339 }
360 340 }
  341 +
361 342 return 0;
362 343 }
363 344