UBI: bugfix in error path
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Mon, 18 Jun 2007 09:06:30 +0000 (12:06 +0300)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Wed, 18 Jul 2007 13:55:55 +0000 (16:55 +0300)
When volume creation fails, we have to set ubi->volumes[vol_id]
back to NULL.

This patch also tweaks some debugging stuff.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
drivers/mtd/ubi/debug.c
drivers/mtd/ubi/debug.h
drivers/mtd/ubi/vmt.c
drivers/mtd/ubi/vtbl.c

index 9a996c5280f9c7a08808ba77ff67d5a603628b0a..310341e5cd43065b8e5e3df1a7afefd56a161a67 100644 (file)
@@ -91,7 +91,7 @@ void ubi_dbg_dump_vol_info(const struct ubi_volume *vol)
 
        if (vol->name_len <= UBI_VOL_NAME_MAX &&
            strnlen(vol->name, vol->name_len + 1) == vol->name_len) {
-               dbg_msg("name          %s", vol->name);
+               dbg_msg("name            %s", vol->name);
        } else {
                dbg_msg("the 1st 5 characters of the name: %c%c%c%c%c",
                        vol->name[0], vol->name[1], vol->name[2],
@@ -117,13 +117,13 @@ void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx)
        dbg_msg("name_len        %d", name_len);
 
        if (r->name[0] == '\0') {
-               dbg_msg("name          NULL");
+               dbg_msg("name            NULL");
                return;
        }
 
        if (name_len <= UBI_VOL_NAME_MAX &&
            strnlen(&r->name[0], name_len + 1) == name_len) {
-               dbg_msg("name          %s", &r->name[0]);
+               dbg_msg("name            %s", &r->name[0]);
        } else {
                dbg_msg("1st 5 characters of the name: %c%c%c%c%c",
                        r->name[0], r->name[1], r->name[2], r->name[3],
index f816ad9a36c00a1987622c09c6f5727c23488044..ff8f39548cd80aaf58cb979d291e609f4d80f214 100644 (file)
@@ -52,7 +52,6 @@ struct ubi_scan_volume;
 struct ubi_scan_leb;
 struct ubi_mkvol_req;
 
-void ubi_dbg_print(int type, const char *func, const char *fmt, ...);
 void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr);
 void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr);
 void ubi_dbg_dump_vol_info(const struct ubi_volume *vol);
@@ -66,7 +65,6 @@ void ubi_dbg_hexdump(const void *buf, int size);
 
 #define dbg_msg(fmt, ...)    ({})
 #define ubi_dbg_dump_stack() ({})
-#define ubi_dbg_print(func, fmt, ...)    ({})
 #define ubi_dbg_dump_ec_hdr(ec_hdr)      ({})
 #define ubi_dbg_dump_vid_hdr(vid_hdr)    ({})
 #define ubi_dbg_dump_vol_info(vol)       ({})
index 6e135996e42d9d32e5c11bffc745c09f4bc3d0a9..a0c6e1e6d465de11cc85c441aecd4d9cde5d875f 100644 (file)
@@ -228,7 +228,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
        for (i = 0; i < ubi->vtbl_slots; i++)
                if (ubi->volumes[i] &&
                    ubi->volumes[i]->name_len == req->name_len &&
-                   strcmp(ubi->volumes[i]->name, req->name) == 0) {
+                   !strcmp(ubi->volumes[i]->name, req->name)) {
                        dbg_err("volume \"%s\" exists (ID %d)", req->name, i);
                        goto out_unlock;
                }
@@ -351,6 +351,7 @@ out_acc:
        spin_lock(&ubi->volumes_lock);
        ubi->rsvd_pebs -= vol->reserved_pebs;
        ubi->avail_pebs += vol->reserved_pebs;
+       ubi->volumes[vol_id] = NULL;
 out_unlock:
        spin_unlock(&ubi->volumes_lock);
        kfree(vol);
@@ -367,6 +368,7 @@ out_sysfs:
        spin_lock(&ubi->volumes_lock);
        ubi->rsvd_pebs -= vol->reserved_pebs;
        ubi->avail_pebs += vol->reserved_pebs;
+       ubi->volumes[vol_id] = NULL;
        spin_unlock(&ubi->volumes_lock);
        volume_sysfs_close(vol);
        return err;
@@ -784,7 +786,7 @@ static void paranoid_check_volume(const struct ubi_device *ubi, int vol_id)
        return;
 
 fail:
-       ubi_err("paranoid check failed");
+       ubi_err("paranoid check failed for volume %d", vol_id);
        ubi_dbg_dump_vol_info(vol);
        ubi_dbg_dump_vtbl_record(&ubi->vtbl[vol_id], vol_id);
        BUG();
index 800ce940a82032cb93f8927bf40b71ee0b67bd64..1f48c76cf6fe1a9dd37988a1ba78b07394b2b043 100644 (file)
@@ -96,9 +96,6 @@ int ubi_change_vtbl_record(struct ubi_device *ubi, int idx,
                vtbl_rec->crc = cpu_to_be32(crc);
        }
 
-       dbg_msg("change record %d", idx);
-       ubi_dbg_dump_vtbl_record(vtbl_rec, idx);
-
        mutex_lock(&ubi->vtbl_mutex);
        memcpy(&ubi->vtbl[idx], vtbl_rec, sizeof(struct ubi_vtbl_record));
        for (i = 0; i < UBI_LAYOUT_VOLUME_EBS; i++) {