Skip to content

Commit ccfeef0

Browse files
committed
Merge branch 'for-linus' of git://git.infradead.org/ubifs-2.6
* 'for-linus' of git://git.infradead.org/ubifs-2.6: UBI: do not select KALLSYMS_ALL UBI: do not compare array with NULL UBI: check if we are in RO mode in the erase routine UBIFS: fix debugging failure in dbg_check_space_info UBIFS: fix error path in dbg_debugfs_init_fs UBIFS: unify error path dbg_debugfs_init_fs UBIFS: do not select KALLSYMS_ALL UBIFS: fix assertion warnings UBIFS: fix oops on error path in read_pnode UBIFS: do not read flash unnecessarily
2 parents 42933ba + 6bef0b6 commit ccfeef0

8 files changed

Lines changed: 61 additions & 31 deletions

File tree

‎drivers/mtd/ubi/Kconfig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ config MTD_UBI_DEBUG
5656
bool "UBI debugging"
5757
depends on SYSFS
5858
select DEBUG_FS
59-
select KALLSYMS_ALL if KALLSYMS && DEBUG_KERNEL
59+
select KALLSYMS
6060
help
6161
This option enables UBI debugging.
6262

‎drivers/mtd/ubi/io.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,12 @@ static int do_sync_erase(struct ubi_device *ubi, int pnum)
344344
wait_queue_head_t wq;
345345

346346
dbg_io("erase PEB %d", pnum);
347+
ubi_assert(pnum >= 0 && pnum < ubi->peb_count);
348+
349+
if (ubi->ro_mode) {
350+
ubi_err("read-only mode");
351+
return -EROFS;
352+
}
347353

348354
retry:
349355
init_waitqueue_head(&wq);
@@ -390,7 +396,7 @@ static int do_sync_erase(struct ubi_device *ubi, int pnum)
390396
if (err)
391397
return err;
392398

393-
if (ubi_dbg_is_erase_failure() && !err) {
399+
if (ubi_dbg_is_erase_failure()) {
394400
dbg_err("cannot erase PEB %d (emulated)", pnum);
395401
return -EIO;
396402
}

‎drivers/mtd/ubi/vmt.c‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -790,11 +790,6 @@ static int paranoid_check_volume(struct ubi_device *ubi, int vol_id)
790790
goto fail;
791791
}
792792

793-
if (!vol->name) {
794-
ubi_err("NULL volume name");
795-
goto fail;
796-
}
797-
798793
n = strnlen(vol->name, vol->name_len + 1);
799794
if (n != vol->name_len) {
800795
ubi_err("bad name_len %lld", n);

‎fs/ubifs/Kconfig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ config UBIFS_FS_DEBUG
4747
bool "Enable debugging support"
4848
depends on UBIFS_FS
4949
select DEBUG_FS
50-
select KALLSYMS_ALL
50+
select KALLSYMS
5151
help
5252
This option enables UBIFS debugging support. It makes sure various
5353
assertions, self-checks, debugging messages and test modes are compiled

‎fs/ubifs/commit.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ int dbg_check_old_index(struct ubifs_info *c, struct ubifs_zbranch *zroot)
577577
size_t sz;
578578

579579
if (!(ubifs_chk_flags & UBIFS_CHK_OLD_IDX))
580-
goto out;
580+
return 0;
581581

582582
INIT_LIST_HEAD(&list);
583583

‎fs/ubifs/debug.c‎

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -972,11 +972,39 @@ void dbg_dump_index(struct ubifs_info *c)
972972
void dbg_save_space_info(struct ubifs_info *c)
973973
{
974974
struct ubifs_debug_info *d = c->dbg;
975-
976-
ubifs_get_lp_stats(c, &d->saved_lst);
975+
int freeable_cnt;
977976

978977
spin_lock(&c->space_lock);
978+
memcpy(&d->saved_lst, &c->lst, sizeof(struct ubifs_lp_stats));
979+
980+
/*
981+
* We use a dirty hack here and zero out @c->freeable_cnt, because it
982+
* affects the free space calculations, and UBIFS might not know about
983+
* all freeable eraseblocks. Indeed, we know about freeable eraseblocks
984+
* only when we read their lprops, and we do this only lazily, upon the
985+
* need. So at any given point of time @c->freeable_cnt might be not
986+
* exactly accurate.
987+
*
988+
* Just one example about the issue we hit when we did not zero
989+
* @c->freeable_cnt.
990+
* 1. The file-system is mounted R/O, c->freeable_cnt is %0. We save the
991+
* amount of free space in @d->saved_free
992+
* 2. We re-mount R/W, which makes UBIFS to read the "lsave"
993+
* information from flash, where we cache LEBs from various
994+
* categories ('ubifs_remount_fs()' -> 'ubifs_lpt_init()'
995+
* -> 'lpt_init_wr()' -> 'read_lsave()' -> 'ubifs_lpt_lookup()'
996+
* -> 'ubifs_get_pnode()' -> 'update_cats()'
997+
* -> 'ubifs_add_to_cat()').
998+
* 3. Lsave contains a freeable eraseblock, and @c->freeable_cnt
999+
* becomes %1.
1000+
* 4. We calculate the amount of free space when the re-mount is
1001+
* finished in 'dbg_check_space_info()' and it does not match
1002+
* @d->saved_free.
1003+
*/
1004+
freeable_cnt = c->freeable_cnt;
1005+
c->freeable_cnt = 0;
9791006
d->saved_free = ubifs_get_free_space_nolock(c);
1007+
c->freeable_cnt = freeable_cnt;
9801008
spin_unlock(&c->space_lock);
9811009
}
9821010

@@ -993,12 +1021,15 @@ int dbg_check_space_info(struct ubifs_info *c)
9931021
{
9941022
struct ubifs_debug_info *d = c->dbg;
9951023
struct ubifs_lp_stats lst;
996-
long long avail, free;
1024+
long long free;
1025+
int freeable_cnt;
9971026

9981027
spin_lock(&c->space_lock);
999-
avail = ubifs_calc_available(c, c->min_idx_lebs);
1028+
freeable_cnt = c->freeable_cnt;
1029+
c->freeable_cnt = 0;
1030+
free = ubifs_get_free_space_nolock(c);
1031+
c->freeable_cnt = freeable_cnt;
10001032
spin_unlock(&c->space_lock);
1001-
free = ubifs_get_free_space(c);
10021033

10031034
if (free != d->saved_free) {
10041035
ubifs_err("free space changed from %lld to %lld",
@@ -2806,40 +2837,38 @@ int dbg_debugfs_init_fs(struct ubifs_info *c)
28062837
struct ubifs_debug_info *d = c->dbg;
28072838

28082839
sprintf(d->dfs_dir_name, "ubi%d_%d", c->vi.ubi_num, c->vi.vol_id);
2809-
d->dfs_dir = debugfs_create_dir(d->dfs_dir_name, dfs_rootdir);
2810-
if (IS_ERR(d->dfs_dir)) {
2811-
err = PTR_ERR(d->dfs_dir);
2812-
ubifs_err("cannot create \"%s\" debugfs directory, error %d\n",
2813-
d->dfs_dir_name, err);
2840+
fname = d->dfs_dir_name;
2841+
dent = debugfs_create_dir(fname, dfs_rootdir);
2842+
if (IS_ERR_OR_NULL(dent))
28142843
goto out;
2815-
}
2844+
d->dfs_dir = dent;
28162845

28172846
fname = "dump_lprops";
28182847
dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, &dfs_fops);
2819-
if (IS_ERR(dent))
2848+
if (IS_ERR_OR_NULL(dent))
28202849
goto out_remove;
28212850
d->dfs_dump_lprops = dent;
28222851

28232852
fname = "dump_budg";
28242853
dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, &dfs_fops);
2825-
if (IS_ERR(dent))
2854+
if (IS_ERR_OR_NULL(dent))
28262855
goto out_remove;
28272856
d->dfs_dump_budg = dent;
28282857

28292858
fname = "dump_tnc";
28302859
dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, &dfs_fops);
2831-
if (IS_ERR(dent))
2860+
if (IS_ERR_OR_NULL(dent))
28322861
goto out_remove;
28332862
d->dfs_dump_tnc = dent;
28342863

28352864
return 0;
28362865

28372866
out_remove:
2838-
err = PTR_ERR(dent);
2839-
ubifs_err("cannot create \"%s\" debugfs directory, error %d\n",
2840-
fname, err);
28412867
debugfs_remove_recursive(d->dfs_dir);
28422868
out:
2869+
err = dent ? PTR_ERR(dent) : -ENODEV;
2870+
ubifs_err("cannot create \"%s\" debugfs directory, error %d\n",
2871+
fname, err);
28432872
return err;
28442873
}
28452874

‎fs/ubifs/lpt.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,10 +1270,9 @@ static int read_pnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip)
12701270
lnum = branch->lnum;
12711271
offs = branch->offs;
12721272
pnode = kzalloc(sizeof(struct ubifs_pnode), GFP_NOFS);
1273-
if (!pnode) {
1274-
err = -ENOMEM;
1275-
goto out;
1276-
}
1273+
if (!pnode)
1274+
return -ENOMEM;
1275+
12771276
if (lnum == 0) {
12781277
/*
12791278
* This pnode was not written which just means that the LEB

‎fs/ubifs/super.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,7 @@ static int ubifs_remount_rw(struct ubifs_info *c)
15681568
mutex_lock(&c->umount_mutex);
15691569
dbg_save_space_info(c);
15701570
c->remounting_rw = 1;
1571+
c->ro_mount = 0;
15711572

15721573
err = check_free_space(c);
15731574
if (err)
@@ -1676,13 +1677,13 @@ static int ubifs_remount_rw(struct ubifs_info *c)
16761677
}
16771678

16781679
dbg_gen("re-mounted read-write");
1679-
c->ro_mount = 0;
16801680
c->remounting_rw = 0;
16811681
err = dbg_check_space_info(c);
16821682
mutex_unlock(&c->umount_mutex);
16831683
return err;
16841684

16851685
out:
1686+
c->ro_mount = 1;
16861687
vfree(c->orph_buf);
16871688
c->orph_buf = NULL;
16881689
if (c->bgt) {

0 commit comments

Comments
 (0)