diff options
-rw-r--r-- | drivers/mtd/mtd_blkdevs.c | 10 | ||||
-rw-r--r-- | drivers/mtd/mtdcore.c | 54 | ||||
-rw-r--r-- | drivers/mtd/mtdcore.h | 15 |
3 files changed, 45 insertions, 34 deletions
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index c82e09bbc5fd..85a52b3c7698 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c | |||
@@ -335,7 +335,8 @@ static struct mtd_notifier blktrans_notifier = { | |||
335 | 335 | ||
336 | int register_mtd_blktrans(struct mtd_blktrans_ops *tr) | 336 | int register_mtd_blktrans(struct mtd_blktrans_ops *tr) |
337 | { | 337 | { |
338 | int ret, i; | 338 | struct mtd_info *mtd; |
339 | int ret; | ||
339 | 340 | ||
340 | /* Register the notifier if/when the first device type is | 341 | /* Register the notifier if/when the first device type is |
341 | registered, to prevent the link/init ordering from fucking | 342 | registered, to prevent the link/init ordering from fucking |
@@ -389,10 +390,9 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr) | |||
389 | INIT_LIST_HEAD(&tr->devs); | 390 | INIT_LIST_HEAD(&tr->devs); |
390 | list_add(&tr->list, &blktrans_majors); | 391 | list_add(&tr->list, &blktrans_majors); |
391 | 392 | ||
392 | for (i=0; i<MAX_MTD_DEVICES; i++) { | 393 | mtd_for_each_device(mtd) |
393 | if (mtd_table[i] && mtd_table[i]->type != MTD_ABSENT) | 394 | if (mtd->type != MTD_ABSENT) |
394 | tr->add_mtd(tr, mtd_table[i]); | 395 | tr->add_mtd(tr, mtd); |
395 | } | ||
396 | 396 | ||
397 | mutex_unlock(&mtd_table_mutex); | 397 | mutex_unlock(&mtd_table_mutex); |
398 | 398 | ||
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; |
diff --git a/drivers/mtd/mtdcore.h b/drivers/mtd/mtdcore.h index a33251f4b872..e2f93a300738 100644 --- a/drivers/mtd/mtdcore.h +++ b/drivers/mtd/mtdcore.h | |||
@@ -9,3 +9,18 @@ | |||
9 | 9 | ||
10 | extern struct mutex mtd_table_mutex; | 10 | extern struct mutex mtd_table_mutex; |
11 | extern struct mtd_info *mtd_table[MAX_MTD_DEVICES]; | 11 | extern struct mtd_info *mtd_table[MAX_MTD_DEVICES]; |
12 | |||
13 | static inline struct mtd_info *__mtd_next_device(int i) | ||
14 | { | ||
15 | while (i < MAX_MTD_DEVICES) { | ||
16 | if (mtd_table[i]) | ||
17 | return mtd_table[i]; | ||
18 | i++; | ||
19 | } | ||
20 | return NULL; | ||
21 | } | ||
22 | |||
23 | #define mtd_for_each_device(mtd) \ | ||
24 | for ((mtd) = __mtd_next_device(0); \ | ||
25 | (mtd) != NULL; \ | ||
26 | (mtd) = __mtd_next_device(mtd->index + 1)) | ||