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