diff options
Diffstat (limited to 'drivers/mtd/mtdcore.c')
-rw-r--r-- | drivers/mtd/mtdcore.c | 54 |
1 files changed, 25 insertions, 29 deletions
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index c356c0a30c3e..402d41723c3f 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c | |||
@@ -381,7 +381,7 @@ int del_mtd_device (struct mtd_info *mtd) | |||
381 | 381 | ||
382 | void register_mtd_user (struct mtd_notifier *new) | 382 | void register_mtd_user (struct mtd_notifier *new) |
383 | { | 383 | { |
384 | int i; | 384 | struct mtd_info *mtd; |
385 | 385 | ||
386 | mutex_lock(&mtd_table_mutex); | 386 | mutex_lock(&mtd_table_mutex); |
387 | 387 | ||
@@ -389,9 +389,8 @@ void register_mtd_user (struct mtd_notifier *new) | |||
389 | 389 | ||
390 | __module_get(THIS_MODULE); | 390 | __module_get(THIS_MODULE); |
391 | 391 | ||
392 | for (i=0; i< MAX_MTD_DEVICES; i++) | 392 | mtd_for_each_device(mtd) |
393 | if (mtd_table[i]) | 393 | new->add(mtd); |
394 | new->add(mtd_table[i]); | ||
395 | 394 | ||
396 | mutex_unlock(&mtd_table_mutex); | 395 | mutex_unlock(&mtd_table_mutex); |
397 | } | 396 | } |
@@ -408,15 +407,14 @@ void register_mtd_user (struct mtd_notifier *new) | |||
408 | 407 | ||
409 | int unregister_mtd_user (struct mtd_notifier *old) | 408 | int unregister_mtd_user (struct mtd_notifier *old) |
410 | { | 409 | { |
411 | int i; | 410 | struct mtd_info *mtd; |
412 | 411 | ||
413 | mutex_lock(&mtd_table_mutex); | 412 | mutex_lock(&mtd_table_mutex); |
414 | 413 | ||
415 | module_put(THIS_MODULE); | 414 | module_put(THIS_MODULE); |
416 | 415 | ||
417 | for (i=0; i< MAX_MTD_DEVICES; i++) | 416 | mtd_for_each_device(mtd) |
418 | if (mtd_table[i]) | 417 | old->remove(mtd); |
419 | old->remove(mtd_table[i]); | ||
420 | 418 | ||
421 | list_del(&old->list); | 419 | list_del(&old->list); |
422 | mutex_unlock(&mtd_table_mutex); | 420 | mutex_unlock(&mtd_table_mutex); |
@@ -438,15 +436,18 @@ int unregister_mtd_user (struct mtd_notifier *old) | |||
438 | 436 | ||
439 | struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num) | 437 | struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num) |
440 | { | 438 | { |
441 | struct mtd_info *ret = NULL; | 439 | struct mtd_info *ret = NULL, *other; |
442 | int i, err = -ENODEV; | 440 | int err = -ENODEV; |
443 | 441 | ||
444 | mutex_lock(&mtd_table_mutex); | 442 | mutex_lock(&mtd_table_mutex); |
445 | 443 | ||
446 | if (num == -1) { | 444 | if (num == -1) { |
447 | for (i=0; i< MAX_MTD_DEVICES; i++) | 445 | mtd_for_each_device(other) { |
448 | if (mtd_table[i] == mtd) | 446 | if (other == mtd) { |
449 | ret = mtd_table[i]; | 447 | ret = mtd; |
448 | break; | ||
449 | } | ||
450 | } | ||
450 | } else if (num >= 0 && num < MAX_MTD_DEVICES) { | 451 | } else if (num >= 0 && num < MAX_MTD_DEVICES) { |
451 | ret = mtd_table[num]; | 452 | ret = mtd_table[num]; |
452 | if (mtd && mtd != ret) | 453 | if (mtd && mtd != ret) |
@@ -487,14 +488,14 @@ out_unlock: | |||
487 | 488 | ||
488 | struct mtd_info *get_mtd_device_nm(const char *name) | 489 | struct mtd_info *get_mtd_device_nm(const char *name) |
489 | { | 490 | { |
490 | int i, err = -ENODEV; | 491 | int err = -ENODEV; |
491 | struct mtd_info *mtd = NULL; | 492 | struct mtd_info *mtd = NULL, *other; |
492 | 493 | ||
493 | mutex_lock(&mtd_table_mutex); | 494 | mutex_lock(&mtd_table_mutex); |
494 | 495 | ||
495 | for (i = 0; i < MAX_MTD_DEVICES; i++) { | 496 | mtd_for_each_device(other) { |
496 | if (mtd_table[i] && !strcmp(name, mtd_table[i]->name)) { | 497 | if (!strcmp(name, other->name)) { |
497 | mtd = mtd_table[i]; | 498 | mtd = other; |
498 | break; | 499 | break; |
499 | } | 500 | } |
500 | } | 501 | } |
@@ -581,14 +582,9 @@ EXPORT_SYMBOL_GPL(default_mtd_writev); | |||
581 | 582 | ||
582 | static struct proc_dir_entry *proc_mtd; | 583 | static struct proc_dir_entry *proc_mtd; |
583 | 584 | ||
584 | static inline int mtd_proc_info (char *buf, int i) | 585 | static inline int mtd_proc_info(char *buf, struct mtd_info *this) |
585 | { | 586 | { |
586 | struct mtd_info *this = mtd_table[i]; | 587 | return sprintf(buf, "mtd%d: %8.8llx %8.8x \"%s\"\n", this->index, |
587 | |||
588 | if (!this) | ||
589 | return 0; | ||
590 | |||
591 | return sprintf(buf, "mtd%d: %8.8llx %8.8x \"%s\"\n", i, | ||
592 | (unsigned long long)this->size, | 588 | (unsigned long long)this->size, |
593 | this->erasesize, this->name); | 589 | this->erasesize, this->name); |
594 | } | 590 | } |
@@ -596,15 +592,15 @@ static inline int mtd_proc_info (char *buf, int i) | |||
596 | static int mtd_read_proc (char *page, char **start, off_t off, int count, | 592 | static int mtd_read_proc (char *page, char **start, off_t off, int count, |
597 | int *eof, void *data_unused) | 593 | int *eof, void *data_unused) |
598 | { | 594 | { |
599 | int len, l, i; | 595 | struct mtd_info *mtd; |
596 | int len, l; | ||
600 | off_t begin = 0; | 597 | off_t begin = 0; |
601 | 598 | ||
602 | mutex_lock(&mtd_table_mutex); | 599 | mutex_lock(&mtd_table_mutex); |
603 | 600 | ||
604 | len = sprintf(page, "dev: size erasesize name\n"); | 601 | len = sprintf(page, "dev: size erasesize name\n"); |
605 | for (i=0; i< MAX_MTD_DEVICES; i++) { | 602 | mtd_for_each_device(mtd) { |
606 | 603 | l = mtd_proc_info(page + len, mtd); | |
607 | l = mtd_proc_info(page + len, i); | ||
608 | len += l; | 604 | len += l; |
609 | if (len+begin > off+count) | 605 | if (len+begin > off+count) |
610 | goto done; | 606 | goto done; |