aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/mtd/ubi/build.c42
-rw-r--r--drivers/mtd/ubi/cdev.c2
-rw-r--r--drivers/mtd/ubi/ubi.h4
3 files changed, 27 insertions, 21 deletions
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 7f6820becf10..9b94427be145 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -58,9 +58,6 @@ static int mtd_devs = 0;
58/* MTD devices specification parameters */ 58/* MTD devices specification parameters */
59static struct mtd_dev_param mtd_dev_param[UBI_MAX_DEVICES]; 59static struct mtd_dev_param mtd_dev_param[UBI_MAX_DEVICES];
60 60
61/* Number of UBI devices in system */
62int ubi_devices_cnt;
63
64/* All UBI devices in system */ 61/* All UBI devices in system */
65struct ubi_device *ubi_devices[UBI_MAX_DEVICES]; 62struct ubi_device *ubi_devices[UBI_MAX_DEVICES];
66 63
@@ -566,26 +563,39 @@ static int attach_mtd_dev(const char *mtd_dev, int vid_hdr_offset,
566 } 563 }
567 564
568 /* Check if we already have the same MTD device attached */ 565 /* Check if we already have the same MTD device attached */
569 for (i = 0; i < ubi_devices_cnt; i++) 566 for (i = 0; i < UBI_MAX_DEVICES; i++)
570 if (ubi_devices[i]->mtd->index == mtd->index) { 567 ubi = ubi_devices[i];
568 if (ubi && ubi->mtd->index == mtd->index) {
571 ubi_err("mtd%d is already attached to ubi%d", 569 ubi_err("mtd%d is already attached to ubi%d",
572 mtd->index, i); 570 mtd->index, i);
573 err = -EINVAL; 571 err = -EINVAL;
574 goto out_mtd; 572 goto out_mtd;
575 } 573 }
576 574
577 ubi = ubi_devices[ubi_devices_cnt] = kzalloc(sizeof(struct ubi_device), 575 ubi = kzalloc(sizeof(struct ubi_device), GFP_KERNEL);
578 GFP_KERNEL);
579 if (!ubi) { 576 if (!ubi) {
580 err = -ENOMEM; 577 err = -ENOMEM;
581 goto out_mtd; 578 goto out_mtd;
582 } 579 }
583 580
584 ubi->ubi_num = ubi_devices_cnt;
585 ubi->mtd = mtd; 581 ubi->mtd = mtd;
586 582
583 /* Search for an empty slot in the @ubi_devices array */
584 ubi->ubi_num = -1;
585 for (i = 0; i < UBI_MAX_DEVICES; i++)
586 if (!ubi_devices[i]) {
587 ubi->ubi_num = i;
588 break;
589 }
590
591 if (ubi->ubi_num == -1) {
592 ubi_err("only %d UBI devices may be created", UBI_MAX_DEVICES);
593 err = -ENFILE;
594 goto out_free;
595 }
596
587 dbg_msg("attaching mtd%d to ubi%d: VID header offset %d data offset %d", 597 dbg_msg("attaching mtd%d to ubi%d: VID header offset %d data offset %d",
588 ubi->mtd->index, ubi_devices_cnt, vid_hdr_offset, data_offset); 598 ubi->mtd->index, ubi->ubi_num, vid_hdr_offset, data_offset);
589 599
590 ubi->vid_hdr_offset = vid_hdr_offset; 600 ubi->vid_hdr_offset = vid_hdr_offset;
591 ubi->leb_start = data_offset; 601 ubi->leb_start = data_offset;
@@ -619,7 +629,7 @@ static int attach_mtd_dev(const char *mtd_dev, int vid_hdr_offset,
619 if (err) 629 if (err)
620 goto out_detach; 630 goto out_detach;
621 631
622 ubi_msg("attached mtd%d to ubi%d", ubi->mtd->index, ubi_devices_cnt); 632 ubi_msg("attached mtd%d to ubi%d", ubi->mtd->index, ubi->ubi_num);
623 ubi_msg("MTD device name: \"%s\"", ubi->mtd->name); 633 ubi_msg("MTD device name: \"%s\"", ubi->mtd->name);
624 ubi_msg("MTD device size: %llu MiB", ubi->flash_size >> 20); 634 ubi_msg("MTD device size: %llu MiB", ubi->flash_size >> 20);
625 ubi_msg("physical eraseblock size: %d bytes (%d KiB)", 635 ubi_msg("physical eraseblock size: %d bytes (%d KiB)",
@@ -648,7 +658,7 @@ static int attach_mtd_dev(const char *mtd_dev, int vid_hdr_offset,
648 wake_up_process(ubi->bgt_thread); 658 wake_up_process(ubi->bgt_thread);
649 } 659 }
650 660
651 ubi_devices_cnt += 1; 661 ubi_devices[ubi->ubi_num] = ubi;
652 return 0; 662 return 0;
653 663
654out_detach: 664out_detach:
@@ -664,7 +674,6 @@ out_free:
664 kfree(ubi); 674 kfree(ubi);
665out_mtd: 675out_mtd:
666 put_mtd_device(mtd); 676 put_mtd_device(mtd);
667 ubi_devices[ubi_devices_cnt] = NULL;
668 return err; 677 return err;
669} 678}
670 679
@@ -689,8 +698,6 @@ static void detach_mtd_dev(struct ubi_device *ubi)
689#endif 698#endif
690 kfree(ubi_devices[ubi_num]); 699 kfree(ubi_devices[ubi_num]);
691 ubi_devices[ubi_num] = NULL; 700 ubi_devices[ubi_num] = NULL;
692 ubi_devices_cnt -= 1;
693 ubi_assert(ubi_devices_cnt >= 0);
694 ubi_msg("mtd%d is detached from ubi%d", mtd_num, ubi_num); 701 ubi_msg("mtd%d is detached from ubi%d", mtd_num, ubi_num);
695} 702}
696 703
@@ -770,10 +777,11 @@ module_init(ubi_init);
770 777
771static void __exit ubi_exit(void) 778static void __exit ubi_exit(void)
772{ 779{
773 int i, n = ubi_devices_cnt; 780 int i;
774 781
775 for (i = 0; i < n; i++) 782 for (i = 0; i < UBI_MAX_DEVICES; i++)
776 detach_mtd_dev(ubi_devices[i]); 783 if (ubi_devices[i])
784 detach_mtd_dev(ubi_devices[i]);
777 kmem_cache_destroy(ubi_wl_entry_slab); 785 kmem_cache_destroy(ubi_wl_entry_slab);
778 kmem_cache_destroy(ubi_ltree_slab); 786 kmem_cache_destroy(ubi_ltree_slab);
779 class_remove_file(ubi_class, &ubi_version); 787 class_remove_file(ubi_class, &ubi_version);
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index 12777da47d3b..7697eda2d58c 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -60,7 +60,7 @@ static struct ubi_device *major_to_device(int major)
60{ 60{
61 int i; 61 int i;
62 62
63 for (i = 0; i < ubi_devices_cnt; i++) 63 for (i = 0; i < UBI_MAX_DEVICES; i++)
64 if (ubi_devices[i] && MAJOR(ubi_devices[i]->cdev.dev) == major) 64 if (ubi_devices[i] && MAJOR(ubi_devices[i]->cdev.dev) == major)
65 return ubi_devices[i]; 65 return ubi_devices[i];
66 BUG(); 66 BUG();
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index b7c93173e77b..23875bf6aa3b 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -94,9 +94,6 @@ enum {
94 UBI_IO_BITFLIPS 94 UBI_IO_BITFLIPS
95}; 95};
96 96
97extern int ubi_devices_cnt;
98extern struct ubi_device *ubi_devices[];
99
100/** 97/**
101 * struct ubi_wl_entry - wear-leveling entry. 98 * struct ubi_wl_entry - wear-leveling entry.
102 * @rb: link in the corresponding RB-tree 99 * @rb: link in the corresponding RB-tree
@@ -401,6 +398,7 @@ extern struct kmem_cache *ubi_ltree_slab;
401extern struct kmem_cache *ubi_wl_entry_slab; 398extern struct kmem_cache *ubi_wl_entry_slab;
402extern struct file_operations ubi_cdev_operations; 399extern struct file_operations ubi_cdev_operations;
403extern struct file_operations ubi_vol_cdev_operations; 400extern struct file_operations ubi_vol_cdev_operations;
401extern struct ubi_device *ubi_devices[];
404extern struct class *ubi_class; 402extern struct class *ubi_class;
405 403
406/* vtbl.c */ 404/* vtbl.c */