aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2008-06-04 10:00:35 -0400
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2008-07-24 06:32:55 -0400
commit505d1caa79cd61a70615e9a7eae2eab85e797a83 (patch)
treeada8f0335b143287bbcec0453c5c5a92d4549102 /drivers/mtd/ubi
parentabc5e92262d87f9c5c628492bffc55f81c7dcb80 (diff)
UBI: do not forget to free internal volumes
UBI forgets to free internal volumes when detaching MTD device. Fix this. Pointed-out-by: Adrian Hunter <ext-adrian.hunter@nokia.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'drivers/mtd/ubi')
-rw-r--r--drivers/mtd/ubi/build.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 7b42b4d05b3a..33205e4c1f5b 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -422,6 +422,10 @@ out_unreg:
422/** 422/**
423 * uif_close - close user interfaces for an UBI device. 423 * uif_close - close user interfaces for an UBI device.
424 * @ubi: UBI device description object 424 * @ubi: UBI device description object
425 *
426 * Note, since this function un-registers UBI volume device objects (@vol->dev),
427 * the memory allocated voe the volumes is freed as well (in the release
428 * function).
425 */ 429 */
426static void uif_close(struct ubi_device *ubi) 430static void uif_close(struct ubi_device *ubi)
427{ 431{
@@ -432,6 +436,21 @@ static void uif_close(struct ubi_device *ubi)
432} 436}
433 437
434/** 438/**
439 * free_internal_volumes - free internal volumes.
440 * @ubi: UBI device description object
441 */
442static void free_internal_volumes(struct ubi_device *ubi)
443{
444 int i;
445
446 for (i = ubi->vtbl_slots;
447 i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) {
448 kfree(ubi->volumes[i]->eba_tbl);
449 kfree(ubi->volumes[i]);
450 }
451}
452
453/**
435 * attach_by_scanning - attach an MTD device using scanning method. 454 * attach_by_scanning - attach an MTD device using scanning method.
436 * @ubi: UBI device descriptor 455 * @ubi: UBI device descriptor
437 * 456 *
@@ -475,6 +494,7 @@ static int attach_by_scanning(struct ubi_device *ubi)
475out_wl: 494out_wl:
476 ubi_wl_close(ubi); 495 ubi_wl_close(ubi);
477out_vtbl: 496out_vtbl:
497 free_internal_volumes(ubi);
478 vfree(ubi->vtbl); 498 vfree(ubi->vtbl);
479out_si: 499out_si:
480 ubi_scan_destroy_si(si); 500 ubi_scan_destroy_si(si);
@@ -650,7 +670,7 @@ static int autoresize(struct ubi_device *ubi, int vol_id)
650 670
651 /* 671 /*
652 * Clear the auto-resize flag in the volume in-memory copy of the 672 * Clear the auto-resize flag in the volume in-memory copy of the
653 * volume table, and 'ubi_resize_volume()' will propogate this change 673 * volume table, and 'ubi_resize_volume()' will propagate this change
654 * to the flash. 674 * to the flash.
655 */ 675 */
656 ubi->vtbl[vol_id].flags &= ~UBI_VTBL_AUTORESIZE_FLG; 676 ubi->vtbl[vol_id].flags &= ~UBI_VTBL_AUTORESIZE_FLG;
@@ -659,7 +679,7 @@ static int autoresize(struct ubi_device *ubi, int vol_id)
659 struct ubi_vtbl_record vtbl_rec; 679 struct ubi_vtbl_record vtbl_rec;
660 680
661 /* 681 /*
662 * No avalilable PEBs to re-size the volume, clear the flag on 682 * No available PEBs to re-size the volume, clear the flag on
663 * flash and exit. 683 * flash and exit.
664 */ 684 */
665 memcpy(&vtbl_rec, &ubi->vtbl[vol_id], 685 memcpy(&vtbl_rec, &ubi->vtbl[vol_id],
@@ -692,7 +712,7 @@ static int autoresize(struct ubi_device *ubi, int vol_id)
692 * 712 *
693 * This function attaches MTD device @mtd_dev to UBI and assign @ubi_num number 713 * This function attaches MTD device @mtd_dev to UBI and assign @ubi_num number
694 * to the newly created UBI device, unless @ubi_num is %UBI_DEV_NUM_AUTO, in 714 * to the newly created UBI device, unless @ubi_num is %UBI_DEV_NUM_AUTO, in
695 * which case this function finds a vacant device nubert and assings it 715 * which case this function finds a vacant device number and assigns it
696 * automatically. Returns the new UBI device number in case of success and a 716 * automatically. Returns the new UBI device number in case of success and a
697 * negative error code in case of failure. 717 * negative error code in case of failure.
698 * 718 *
@@ -841,6 +861,7 @@ out_uif:
841 uif_close(ubi); 861 uif_close(ubi);
842out_detach: 862out_detach:
843 ubi_wl_close(ubi); 863 ubi_wl_close(ubi);
864 free_internal_volumes(ubi);
844 vfree(ubi->vtbl); 865 vfree(ubi->vtbl);
845out_free: 866out_free:
846 vfree(ubi->peb_buf1); 867 vfree(ubi->peb_buf1);
@@ -903,6 +924,7 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
903 924
904 uif_close(ubi); 925 uif_close(ubi);
905 ubi_wl_close(ubi); 926 ubi_wl_close(ubi);
927 free_internal_volumes(ubi);
906 vfree(ubi->vtbl); 928 vfree(ubi->vtbl);
907 put_mtd_device(ubi->mtd); 929 put_mtd_device(ubi->mtd);
908 vfree(ubi->peb_buf1); 930 vfree(ubi->peb_buf1);