aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/devices/block2mtd.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/devices/block2mtd.c')
-rw-r--r--drivers/mtd/devices/block2mtd.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index 4160b8334c53..0d98c223c5fc 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -4,7 +4,7 @@
4 * block2mtd.c - create an mtd from a block device 4 * block2mtd.c - create an mtd from a block device
5 * 5 *
6 * Copyright (C) 2001,2002 Simon Evans <spse@secret.org.uk> 6 * Copyright (C) 2001,2002 Simon Evans <spse@secret.org.uk>
7 * Copyright (C) 2004,2005 Jrn Engel <joern@wh.fh-wedel.de> 7 * Copyright (C) 2004-2006 Jรถrn Engel <joern@wh.fh-wedel.de>
8 * 8 *
9 * Licence: GPL 9 * Licence: GPL
10 */ 10 */
@@ -331,7 +331,6 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
331 dev->mtd.writev = default_mtd_writev; 331 dev->mtd.writev = default_mtd_writev;
332 dev->mtd.sync = block2mtd_sync; 332 dev->mtd.sync = block2mtd_sync;
333 dev->mtd.read = block2mtd_read; 333 dev->mtd.read = block2mtd_read;
334 dev->mtd.readv = default_mtd_readv;
335 dev->mtd.priv = dev; 334 dev->mtd.priv = dev;
336 dev->mtd.owner = THIS_MODULE; 335 dev->mtd.owner = THIS_MODULE;
337 336
@@ -351,6 +350,12 @@ devinit_err:
351} 350}
352 351
353 352
353/* This function works similar to reguler strtoul. In addition, it
354 * allows some suffixes for a more human-readable number format:
355 * ki, Ki, kiB, KiB - multiply result with 1024
356 * Mi, MiB - multiply result with 1024^2
357 * Gi, GiB - multiply result with 1024^3
358 */
354static int ustrtoul(const char *cp, char **endp, unsigned int base) 359static int ustrtoul(const char *cp, char **endp, unsigned int base)
355{ 360{
356 unsigned long result = simple_strtoul(cp, endp, base); 361 unsigned long result = simple_strtoul(cp, endp, base);
@@ -359,11 +364,16 @@ static int ustrtoul(const char *cp, char **endp, unsigned int base)
359 result *= 1024; 364 result *= 1024;
360 case 'M': 365 case 'M':
361 result *= 1024; 366 result *= 1024;
367 case 'K':
362 case 'k': 368 case 'k':
363 result *= 1024; 369 result *= 1024;
364 /* By dwmw2 editorial decree, "ki", "Mi" or "Gi" are to be used. */ 370 /* By dwmw2 editorial decree, "ki", "Mi" or "Gi" are to be used. */
365 if ((*endp)[1] == 'i') 371 if ((*endp)[1] == 'i') {
366 (*endp) += 2; 372 if ((*endp)[2] == 'B')
373 (*endp) += 3;
374 else
375 (*endp) += 2;
376 }
367 } 377 }
368 return result; 378 return result;
369} 379}
@@ -418,7 +428,8 @@ static inline void kill_final_newline(char *str)
418 428
419static int block2mtd_setup(const char *val, struct kernel_param *kp) 429static int block2mtd_setup(const char *val, struct kernel_param *kp)
420{ 430{
421 char buf[80+12], *str=buf; /* 80 for device, 12 for erase size */ 431 char buf[80+12]; /* 80 for device, 12 for erase size */
432 char *str = buf;
422 char *token[2]; 433 char *token[2];
423 char *name; 434 char *name;
424 size_t erase_size = PAGE_SIZE; 435 size_t erase_size = PAGE_SIZE;
@@ -430,7 +441,7 @@ static int block2mtd_setup(const char *val, struct kernel_param *kp)
430 strcpy(str, val); 441 strcpy(str, val);
431 kill_final_newline(str); 442 kill_final_newline(str);
432 443
433 for (i=0; i<2; i++) 444 for (i = 0; i < 2; i++)
434 token[i] = strsep(&str, ","); 445 token[i] = strsep(&str, ",");
435 446
436 if (str) 447 if (str)
@@ -449,8 +460,10 @@ static int block2mtd_setup(const char *val, struct kernel_param *kp)
449 460
450 if (token[1]) { 461 if (token[1]) {
451 ret = parse_num(&erase_size, token[1]); 462 ret = parse_num(&erase_size, token[1]);
452 if (ret) 463 if (ret) {
464 kfree(name);
453 parse_err("illegal erase size"); 465 parse_err("illegal erase size");
466 }
454 } 467 }
455 468
456 add_device(name, erase_size); 469 add_device(name, erase_size);