aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ubifs
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-02-26 17:51:14 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-26 17:51:14 -0500
commita6590b9f01dca2d45a38b8387f59812c44f68a2f (patch)
treecabc65bb93d92763538d04cdfba1e62eaffc8a76 /fs/ubifs
parent1085db4aa68ce960f8c987a67a104ba834022fef (diff)
parent8afd500cb52a5d00bab4525dd5a560d199f979b9 (diff)
Merge tag 'upstream-3.9-rc1' of git://git.infradead.org/linux-ubifs
Pull ubifs updates from Artem Bityutskiy: "It's been quite silent and we have only a couple of bug-fixes for the orphans handling code plus one cosmetic change." * tag 'upstream-3.9-rc1' of git://git.infradead.org/linux-ubifs: UBIFS: fix double free of ubifs_orphan objects UBIFS: fix use of freed ubifs_orphan objects UBIFS: rename random32() to prandom_u32()
Diffstat (limited to 'fs/ubifs')
-rw-r--r--fs/ubifs/debug.c8
-rw-r--r--fs/ubifs/lpt_commit.c14
-rw-r--r--fs/ubifs/orphan.c12
-rw-r--r--fs/ubifs/tnc_commit.c2
-rw-r--r--fs/ubifs/ubifs.h6
5 files changed, 27 insertions, 15 deletions
diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c
index 12817ffc7345..7f60e900edff 100644
--- a/fs/ubifs/debug.c
+++ b/fs/ubifs/debug.c
@@ -2459,7 +2459,7 @@ error_dump:
2459 2459
2460static inline int chance(unsigned int n, unsigned int out_of) 2460static inline int chance(unsigned int n, unsigned int out_of)
2461{ 2461{
2462 return !!((random32() % out_of) + 1 <= n); 2462 return !!((prandom_u32() % out_of) + 1 <= n);
2463 2463
2464} 2464}
2465 2465
@@ -2477,13 +2477,13 @@ static int power_cut_emulated(struct ubifs_info *c, int lnum, int write)
2477 if (chance(1, 2)) { 2477 if (chance(1, 2)) {
2478 d->pc_delay = 1; 2478 d->pc_delay = 1;
2479 /* Fail withing 1 minute */ 2479 /* Fail withing 1 minute */
2480 delay = random32() % 60000; 2480 delay = prandom_u32() % 60000;
2481 d->pc_timeout = jiffies; 2481 d->pc_timeout = jiffies;
2482 d->pc_timeout += msecs_to_jiffies(delay); 2482 d->pc_timeout += msecs_to_jiffies(delay);
2483 ubifs_warn("failing after %lums", delay); 2483 ubifs_warn("failing after %lums", delay);
2484 } else { 2484 } else {
2485 d->pc_delay = 2; 2485 d->pc_delay = 2;
2486 delay = random32() % 10000; 2486 delay = prandom_u32() % 10000;
2487 /* Fail within 10000 operations */ 2487 /* Fail within 10000 operations */
2488 d->pc_cnt_max = delay; 2488 d->pc_cnt_max = delay;
2489 ubifs_warn("failing after %lu calls", delay); 2489 ubifs_warn("failing after %lu calls", delay);
@@ -2563,7 +2563,7 @@ static int corrupt_data(const struct ubifs_info *c, const void *buf,
2563 unsigned int from, to, ffs = chance(1, 2); 2563 unsigned int from, to, ffs = chance(1, 2);
2564 unsigned char *p = (void *)buf; 2564 unsigned char *p = (void *)buf;
2565 2565
2566 from = random32() % (len + 1); 2566 from = prandom_u32() % (len + 1);
2567 /* Corruption may only span one max. write unit */ 2567 /* Corruption may only span one max. write unit */
2568 to = min(len, ALIGN(from, c->max_write_size)); 2568 to = min(len, ALIGN(from, c->max_write_size));
2569 2569
diff --git a/fs/ubifs/lpt_commit.c b/fs/ubifs/lpt_commit.c
index 9daaeef675dd..4b826abb1528 100644
--- a/fs/ubifs/lpt_commit.c
+++ b/fs/ubifs/lpt_commit.c
@@ -2007,28 +2007,28 @@ static int dbg_populate_lsave(struct ubifs_info *c)
2007 2007
2008 if (!dbg_is_chk_gen(c)) 2008 if (!dbg_is_chk_gen(c))
2009 return 0; 2009 return 0;
2010 if (random32() & 3) 2010 if (prandom_u32() & 3)
2011 return 0; 2011 return 0;
2012 2012
2013 for (i = 0; i < c->lsave_cnt; i++) 2013 for (i = 0; i < c->lsave_cnt; i++)
2014 c->lsave[i] = c->main_first; 2014 c->lsave[i] = c->main_first;
2015 2015
2016 list_for_each_entry(lprops, &c->empty_list, list) 2016 list_for_each_entry(lprops, &c->empty_list, list)
2017 c->lsave[random32() % c->lsave_cnt] = lprops->lnum; 2017 c->lsave[prandom_u32() % c->lsave_cnt] = lprops->lnum;
2018 list_for_each_entry(lprops, &c->freeable_list, list) 2018 list_for_each_entry(lprops, &c->freeable_list, list)
2019 c->lsave[random32() % c->lsave_cnt] = lprops->lnum; 2019 c->lsave[prandom_u32() % c->lsave_cnt] = lprops->lnum;
2020 list_for_each_entry(lprops, &c->frdi_idx_list, list) 2020 list_for_each_entry(lprops, &c->frdi_idx_list, list)
2021 c->lsave[random32() % c->lsave_cnt] = lprops->lnum; 2021 c->lsave[prandom_u32() % c->lsave_cnt] = lprops->lnum;
2022 2022
2023 heap = &c->lpt_heap[LPROPS_DIRTY_IDX - 1]; 2023 heap = &c->lpt_heap[LPROPS_DIRTY_IDX - 1];
2024 for (i = 0; i < heap->cnt; i++) 2024 for (i = 0; i < heap->cnt; i++)
2025 c->lsave[random32() % c->lsave_cnt] = heap->arr[i]->lnum; 2025 c->lsave[prandom_u32() % c->lsave_cnt] = heap->arr[i]->lnum;
2026 heap = &c->lpt_heap[LPROPS_DIRTY - 1]; 2026 heap = &c->lpt_heap[LPROPS_DIRTY - 1];
2027 for (i = 0; i < heap->cnt; i++) 2027 for (i = 0; i < heap->cnt; i++)
2028 c->lsave[random32() % c->lsave_cnt] = heap->arr[i]->lnum; 2028 c->lsave[prandom_u32() % c->lsave_cnt] = heap->arr[i]->lnum;
2029 heap = &c->lpt_heap[LPROPS_FREE - 1]; 2029 heap = &c->lpt_heap[LPROPS_FREE - 1];
2030 for (i = 0; i < heap->cnt; i++) 2030 for (i = 0; i < heap->cnt; i++)
2031 c->lsave[random32() % c->lsave_cnt] = heap->arr[i]->lnum; 2031 c->lsave[prandom_u32() % c->lsave_cnt] = heap->arr[i]->lnum;
2032 2032
2033 return 1; 2033 return 1;
2034} 2034}
diff --git a/fs/ubifs/orphan.c b/fs/ubifs/orphan.c
index 769701ccb5c9..ba32da3fe08a 100644
--- a/fs/ubifs/orphan.c
+++ b/fs/ubifs/orphan.c
@@ -126,13 +126,14 @@ void ubifs_delete_orphan(struct ubifs_info *c, ino_t inum)
126 else if (inum > o->inum) 126 else if (inum > o->inum)
127 p = p->rb_right; 127 p = p->rb_right;
128 else { 128 else {
129 if (o->dnext) { 129 if (o->del) {
130 spin_unlock(&c->orphan_lock); 130 spin_unlock(&c->orphan_lock);
131 dbg_gen("deleted twice ino %lu", 131 dbg_gen("deleted twice ino %lu",
132 (unsigned long)inum); 132 (unsigned long)inum);
133 return; 133 return;
134 } 134 }
135 if (o->cnext) { 135 if (o->cmt) {
136 o->del = 1;
136 o->dnext = c->orph_dnext; 137 o->dnext = c->orph_dnext;
137 c->orph_dnext = o; 138 c->orph_dnext = o;
138 spin_unlock(&c->orphan_lock); 139 spin_unlock(&c->orphan_lock);
@@ -172,7 +173,9 @@ int ubifs_orphan_start_commit(struct ubifs_info *c)
172 last = &c->orph_cnext; 173 last = &c->orph_cnext;
173 list_for_each_entry(orphan, &c->orph_new, new_list) { 174 list_for_each_entry(orphan, &c->orph_new, new_list) {
174 ubifs_assert(orphan->new); 175 ubifs_assert(orphan->new);
176 ubifs_assert(!orphan->cmt);
175 orphan->new = 0; 177 orphan->new = 0;
178 orphan->cmt = 1;
176 *last = orphan; 179 *last = orphan;
177 last = &orphan->cnext; 180 last = &orphan->cnext;
178 } 181 }
@@ -299,7 +302,9 @@ static int write_orph_node(struct ubifs_info *c, int atomic)
299 cnext = c->orph_cnext; 302 cnext = c->orph_cnext;
300 for (i = 0; i < cnt; i++) { 303 for (i = 0; i < cnt; i++) {
301 orphan = cnext; 304 orphan = cnext;
305 ubifs_assert(orphan->cmt);
302 orph->inos[i] = cpu_to_le64(orphan->inum); 306 orph->inos[i] = cpu_to_le64(orphan->inum);
307 orphan->cmt = 0;
303 cnext = orphan->cnext; 308 cnext = orphan->cnext;
304 orphan->cnext = NULL; 309 orphan->cnext = NULL;
305 } 310 }
@@ -378,6 +383,7 @@ static int consolidate(struct ubifs_info *c)
378 list_for_each_entry(orphan, &c->orph_list, list) { 383 list_for_each_entry(orphan, &c->orph_list, list) {
379 if (orphan->new) 384 if (orphan->new)
380 continue; 385 continue;
386 orphan->cmt = 1;
381 *last = orphan; 387 *last = orphan;
382 last = &orphan->cnext; 388 last = &orphan->cnext;
383 cnt += 1; 389 cnt += 1;
@@ -442,6 +448,7 @@ static void erase_deleted(struct ubifs_info *c)
442 orphan = dnext; 448 orphan = dnext;
443 dnext = orphan->dnext; 449 dnext = orphan->dnext;
444 ubifs_assert(!orphan->new); 450 ubifs_assert(!orphan->new);
451 ubifs_assert(orphan->del);
445 rb_erase(&orphan->rb, &c->orph_tree); 452 rb_erase(&orphan->rb, &c->orph_tree);
446 list_del(&orphan->list); 453 list_del(&orphan->list);
447 c->tot_orphans -= 1; 454 c->tot_orphans -= 1;
@@ -531,6 +538,7 @@ static int insert_dead_orphan(struct ubifs_info *c, ino_t inum)
531 rb_link_node(&orphan->rb, parent, p); 538 rb_link_node(&orphan->rb, parent, p);
532 rb_insert_color(&orphan->rb, &c->orph_tree); 539 rb_insert_color(&orphan->rb, &c->orph_tree);
533 list_add_tail(&orphan->list, &c->orph_list); 540 list_add_tail(&orphan->list, &c->orph_list);
541 orphan->del = 1;
534 orphan->dnext = c->orph_dnext; 542 orphan->dnext = c->orph_dnext;
535 c->orph_dnext = orphan; 543 c->orph_dnext = orphan;
536 dbg_mnt("ino %lu, new %d, tot %d", (unsigned long)inum, 544 dbg_mnt("ino %lu, new %d, tot %d", (unsigned long)inum,
diff --git a/fs/ubifs/tnc_commit.c b/fs/ubifs/tnc_commit.c
index 523bbad69c0c..52a6559275c4 100644
--- a/fs/ubifs/tnc_commit.c
+++ b/fs/ubifs/tnc_commit.c
@@ -683,7 +683,7 @@ static int alloc_idx_lebs(struct ubifs_info *c, int cnt)
683 c->ilebs[c->ileb_cnt++] = lnum; 683 c->ilebs[c->ileb_cnt++] = lnum;
684 dbg_cmt("LEB %d", lnum); 684 dbg_cmt("LEB %d", lnum);
685 } 685 }
686 if (dbg_is_chk_index(c) && !(random32() & 7)) 686 if (dbg_is_chk_index(c) && !(prandom_u32() & 7))
687 return -ENOSPC; 687 return -ENOSPC;
688 return 0; 688 return 0;
689} 689}
diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h
index d133c276fe05..b2babce4d70f 100644
--- a/fs/ubifs/ubifs.h
+++ b/fs/ubifs/ubifs.h
@@ -904,6 +904,8 @@ struct ubifs_budget_req {
904 * @dnext: next orphan to delete 904 * @dnext: next orphan to delete
905 * @inum: inode number 905 * @inum: inode number
906 * @new: %1 => added since the last commit, otherwise %0 906 * @new: %1 => added since the last commit, otherwise %0
907 * @cmt: %1 => commit pending, otherwise %0
908 * @del: %1 => delete pending, otherwise %0
907 */ 909 */
908struct ubifs_orphan { 910struct ubifs_orphan {
909 struct rb_node rb; 911 struct rb_node rb;
@@ -912,7 +914,9 @@ struct ubifs_orphan {
912 struct ubifs_orphan *cnext; 914 struct ubifs_orphan *cnext;
913 struct ubifs_orphan *dnext; 915 struct ubifs_orphan *dnext;
914 ino_t inum; 916 ino_t inum;
915 int new; 917 unsigned new:1;
918 unsigned cmt:1;
919 unsigned del:1;
916}; 920};
917 921
918/** 922/**