Merge branch 'stable-3.2' into pandora-3.2
[pandora-kernel.git] / drivers / mtd / ubi / build.c
index 7bf60f9..44465ef 100644 (file)
@@ -550,10 +550,10 @@ static void uif_close(struct ubi_device *ubi)
 }
 
 /**
- * free_internal_volumes - free internal volumes.
+ * ubi_free_internal_volumes - free internal volumes.
  * @ubi: UBI device description object
  */
-static void free_internal_volumes(struct ubi_device *ubi)
+void ubi_free_internal_volumes(struct ubi_device *ubi)
 {
        int i;
 
@@ -564,59 +564,6 @@ static void free_internal_volumes(struct ubi_device *ubi)
        }
 }
 
-/**
- * attach_by_scanning - attach an MTD device using scanning method.
- * @ubi: UBI device descriptor
- *
- * This function returns zero in case of success and a negative error code in
- * case of failure.
- *
- * Note, currently this is the only method to attach UBI devices. Hopefully in
- * the future we'll have more scalable attaching methods and avoid full media
- * scanning. But even in this case scanning will be needed as a fall-back
- * attaching method if there are some on-flash table corruptions.
- */
-static int attach_by_scanning(struct ubi_device *ubi)
-{
-       int err;
-       struct ubi_attach_info *ai;
-
-       ai = ubi_scan(ubi);
-       if (IS_ERR(ai))
-               return PTR_ERR(ai);
-
-       ubi->bad_peb_count = ai->bad_peb_count;
-       ubi->good_peb_count = ubi->peb_count - ubi->bad_peb_count;
-       ubi->corr_peb_count = ai->corr_peb_count;
-       ubi->max_ec = ai->max_ec;
-       ubi->mean_ec = ai->mean_ec;
-       ubi_msg("max. sequence number:       %llu", ai->max_sqnum);
-
-       err = ubi_read_volume_table(ubi, ai);
-       if (err)
-               goto out_ai;
-
-       err = ubi_wl_init_scan(ubi, ai);
-       if (err)
-               goto out_vtbl;
-
-       err = ubi_eba_init_scan(ubi, ai);
-       if (err)
-               goto out_wl;
-
-       ubi_destroy_ai(ai);
-       return 0;
-
-out_wl:
-       ubi_wl_close(ubi);
-out_vtbl:
-       free_internal_volumes(ubi);
-       vfree(ubi->vtbl);
-out_ai:
-       ubi_destroy_ai(ai);
-       return err;
-}
-
 /**
  * io_init - initialize I/O sub-system for a given UBI device.
  * @ubi: UBI device description object
@@ -812,6 +759,11 @@ static int autoresize(struct ubi_device *ubi, int vol_id)
        struct ubi_volume *vol = ubi->volumes[vol_id];
        int err, old_reserved_pebs = vol->reserved_pebs;
 
+       if (ubi->ro_mode) {
+               ubi_warn("skip auto-resize because of R/O mode");
+               return 0;
+       }
+
        /*
         * Clear the auto-resize flag in the volume in-memory copy of the
         * volume table, and 'ubi_resize_volume()' will propagate this change
@@ -949,9 +901,9 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
        if (err)
                goto out_free;
 
-       err = attach_by_scanning(ubi);
+       err = ubi_attach(ubi);
        if (err) {
-               ubi_err("failed to attach by scanning, error %d", err);
+               ubi_err("failed to attach mtd%d, error %d", mtd->index, err);
                goto out_debugging;
        }
 
@@ -1016,7 +968,7 @@ out_uif:
        uif_close(ubi);
 out_detach:
        ubi_wl_close(ubi);
-       free_internal_volumes(ubi);
+       ubi_free_internal_volumes(ubi);
        vfree(ubi->vtbl);
 out_debugging:
        ubi_debugging_exit_dev(ubi);
@@ -1088,7 +1040,7 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
        ubi_debugfs_exit_dev(ubi);
        uif_close(ubi);
        ubi_wl_close(ubi);
-       free_internal_volumes(ubi);
+       ubi_free_internal_volumes(ubi);
        vfree(ubi->vtbl);
        put_mtd_device(ubi->mtd);
        ubi_debugging_exit_dev(ubi);