Skip to content

Commit e3a251e

Browse files
committed
Merge tag 'upstream-5.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubifs
Pull UBI/UBIFS/JFFS2 updates from Richard Weinberger: "This pull request contains mostly fixes for UBI, UBIFS and JFFS2: UBI: - Fix a regression around producing a anchor PEB for fastmap. Due to a change in our locking fastmap was unable to produce fresh anchors an re-used the existing one a way to often. UBIFS: - Fixes for endianness. A few places blindly assumed little endian. - Fix for a memory leak in the orphan code. - Fix for a possible crash during a commit. - Revert a wrong bugfix. JFFS2: - Revert a bad bugfix (false positive from a code checking tool)" * tag 'upstream-5.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubifs: Revert "jffs2: Fix possible null-pointer dereferences in jffs2_add_frag_to_fragtree()" ubi: Fix producing anchor PEBs ubifs: ubifs_tnc_start_commit: Fix OOB in layout_in_gaps ubifs: do_kill_orphans: Fix a memory leak bug Revert "ubifs: Fix memory leak bug in alloc_ubifs_info() error path" ubifs: Fix type of sup->hash_algo ubifs: Fixed missed le64_to_cpu() in journal ubifs: Force prandom result to __le32 ubifs: Remove obsolete TODO from dfs_file_write() ubi: Fix warning static is not at beginning of declaration ubi: Print skip_check in ubi_dump_vol_info()
2 parents 97eeb4d + 6e78c01 commit e3a251e

File tree

13 files changed

+85
-77
lines changed

13 files changed

+85
-77
lines changed

drivers/mtd/ubi/debug.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ void ubi_dump_vol_info(const struct ubi_volume *vol)
107107
pr_err("\tlast_eb_bytes %d\n", vol->last_eb_bytes);
108108
pr_err("\tcorrupted %d\n", vol->corrupted);
109109
pr_err("\tupd_marker %d\n", vol->upd_marker);
110+
pr_err("\tskip_check %d\n", vol->skip_check);
110111

111112
if (vol->name_len <= UBI_VOL_NAME_MAX &&
112113
strnlen(vol->name, vol->name_len + 1) == vol->name_len) {

drivers/mtd/ubi/fastmap-wl.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,6 @@ static void return_unused_pool_pebs(struct ubi_device *ubi,
5757
}
5858
}
5959

60-
static int anchor_pebs_available(struct rb_root *root)
61-
{
62-
struct rb_node *p;
63-
struct ubi_wl_entry *e;
64-
65-
ubi_rb_for_each_entry(p, e, root, u.rb)
66-
if (e->pnum < UBI_FM_MAX_START)
67-
return 1;
68-
69-
return 0;
70-
}
71-
7260
/**
7361
* ubi_wl_get_fm_peb - find a physical erase block with a given maximal number.
7462
* @ubi: UBI device description object
@@ -277,8 +265,26 @@ static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi)
277265
int ubi_ensure_anchor_pebs(struct ubi_device *ubi)
278266
{
279267
struct ubi_work *wrk;
268+
struct ubi_wl_entry *anchor;
280269

281270
spin_lock(&ubi->wl_lock);
271+
272+
/* Do we already have an anchor? */
273+
if (ubi->fm_anchor) {
274+
spin_unlock(&ubi->wl_lock);
275+
return 0;
276+
}
277+
278+
/* See if we can find an anchor PEB on the list of free PEBs */
279+
anchor = ubi_wl_get_fm_peb(ubi, 1);
280+
if (anchor) {
281+
ubi->fm_anchor = anchor;
282+
spin_unlock(&ubi->wl_lock);
283+
return 0;
284+
}
285+
286+
/* No luck, trigger wear leveling to produce a new anchor PEB */
287+
ubi->fm_do_produce_anchor = 1;
282288
if (ubi->wl_scheduled) {
283289
spin_unlock(&ubi->wl_lock);
284290
return 0;
@@ -294,7 +300,6 @@ int ubi_ensure_anchor_pebs(struct ubi_device *ubi)
294300
return -ENOMEM;
295301
}
296302

297-
wrk->anchor = 1;
298303
wrk->func = &wear_leveling_worker;
299304
__schedule_ubi_work(ubi, wrk);
300305
return 0;

drivers/mtd/ubi/fastmap.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,14 +1540,6 @@ int ubi_update_fastmap(struct ubi_device *ubi)
15401540
return 0;
15411541
}
15421542

1543-
ret = ubi_ensure_anchor_pebs(ubi);
1544-
if (ret) {
1545-
up_write(&ubi->fm_eba_sem);
1546-
up_write(&ubi->work_sem);
1547-
up_write(&ubi->fm_protect);
1548-
return ret;
1549-
}
1550-
15511543
new_fm = kzalloc(sizeof(*new_fm), GFP_KERNEL);
15521544
if (!new_fm) {
15531545
up_write(&ubi->fm_eba_sem);
@@ -1618,7 +1610,8 @@ int ubi_update_fastmap(struct ubi_device *ubi)
16181610
}
16191611

16201612
spin_lock(&ubi->wl_lock);
1621-
tmp_e = ubi_wl_get_fm_peb(ubi, 1);
1613+
tmp_e = ubi->fm_anchor;
1614+
ubi->fm_anchor = NULL;
16221615
spin_unlock(&ubi->wl_lock);
16231616

16241617
if (old_fm) {
@@ -1670,6 +1663,9 @@ int ubi_update_fastmap(struct ubi_device *ubi)
16701663
up_write(&ubi->work_sem);
16711664
up_write(&ubi->fm_protect);
16721665
kfree(old_fm);
1666+
1667+
ubi_ensure_anchor_pebs(ubi);
1668+
16731669
return ret;
16741670

16751671
err:

drivers/mtd/ubi/ubi.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ struct ubi_debug_info {
491491
* @fm_work: fastmap work queue
492492
* @fm_work_scheduled: non-zero if fastmap work was scheduled
493493
* @fast_attach: non-zero if UBI was attached by fastmap
494+
* @fm_anchor: The next anchor PEB to use for fastmap
495+
* @fm_do_produce_anchor: If true produce an anchor PEB in wl
494496
*
495497
* @used: RB-tree of used physical eraseblocks
496498
* @erroneous: RB-tree of erroneous used physical eraseblocks
@@ -599,6 +601,8 @@ struct ubi_device {
599601
struct work_struct fm_work;
600602
int fm_work_scheduled;
601603
int fast_attach;
604+
struct ubi_wl_entry *fm_anchor;
605+
int fm_do_produce_anchor;
602606

603607
/* Wear-leveling sub-system's stuff */
604608
struct rb_root used;
@@ -789,7 +793,6 @@ struct ubi_attach_info {
789793
* @vol_id: the volume ID on which this erasure is being performed
790794
* @lnum: the logical eraseblock number
791795
* @torture: if the physical eraseblock has to be tortured
792-
* @anchor: produce a anchor PEB to by used by fastmap
793796
*
794797
* The @func pointer points to the worker function. If the @shutdown argument is
795798
* not zero, the worker has to free the resources and exit immediately as the
@@ -805,7 +808,6 @@ struct ubi_work {
805808
int vol_id;
806809
int lnum;
807810
int torture;
808-
int anchor;
809811
};
810812

811813
#include "debug.h"
@@ -968,7 +970,7 @@ int ubi_fastmap_init_checkmap(struct ubi_volume *vol, int leb_count);
968970
void ubi_fastmap_destroy_checkmap(struct ubi_volume *vol);
969971
#else
970972
static inline int ubi_update_fastmap(struct ubi_device *ubi) { return 0; }
971-
int static inline ubi_fastmap_init_checkmap(struct ubi_volume *vol, int leb_count) { return 0; }
973+
static inline int ubi_fastmap_init_checkmap(struct ubi_volume *vol, int leb_count) { return 0; }
972974
static inline void ubi_fastmap_destroy_checkmap(struct ubi_volume *vol) {}
973975
#endif
974976

drivers/mtd/ubi/wl.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,6 @@ static struct ubi_wl_entry *find_wl_entry(struct ubi_device *ubi,
339339
}
340340
}
341341

342-
/* If no fastmap has been written and this WL entry can be used
343-
* as anchor PEB, hold it back and return the second best WL entry
344-
* such that fastmap can use the anchor PEB later. */
345-
if (prev_e && !ubi->fm_disabled &&
346-
!ubi->fm && e->pnum < UBI_FM_MAX_START)
347-
return prev_e;
348-
349342
return e;
350343
}
351344

@@ -656,9 +649,6 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
656649
{
657650
int err, scrubbing = 0, torture = 0, protect = 0, erroneous = 0;
658651
int erase = 0, keep = 0, vol_id = -1, lnum = -1;
659-
#ifdef CONFIG_MTD_UBI_FASTMAP
660-
int anchor = wrk->anchor;
661-
#endif
662652
struct ubi_wl_entry *e1, *e2;
663653
struct ubi_vid_io_buf *vidb;
664654
struct ubi_vid_hdr *vid_hdr;
@@ -698,11 +688,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
698688
}
699689

700690
#ifdef CONFIG_MTD_UBI_FASTMAP
701-
/* Check whether we need to produce an anchor PEB */
702-
if (!anchor)
703-
anchor = !anchor_pebs_available(&ubi->free);
704-
705-
if (anchor) {
691+
if (ubi->fm_do_produce_anchor) {
706692
e1 = find_anchor_wl_entry(&ubi->used);
707693
if (!e1)
708694
goto out_cancel;
@@ -719,6 +705,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
719705
self_check_in_wl_tree(ubi, e1, &ubi->used);
720706
rb_erase(&e1->u.rb, &ubi->used);
721707
dbg_wl("anchor-move PEB %d to PEB %d", e1->pnum, e2->pnum);
708+
ubi->fm_do_produce_anchor = 0;
722709
} else if (!ubi->scrub.rb_node) {
723710
#else
724711
if (!ubi->scrub.rb_node) {
@@ -1051,7 +1038,6 @@ static int ensure_wear_leveling(struct ubi_device *ubi, int nested)
10511038
goto out_cancel;
10521039
}
10531040

1054-
wrk->anchor = 0;
10551041
wrk->func = &wear_leveling_worker;
10561042
if (nested)
10571043
__schedule_ubi_work(ubi, wrk);
@@ -1093,8 +1079,15 @@ static int __erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk)
10931079
err = sync_erase(ubi, e, wl_wrk->torture);
10941080
if (!err) {
10951081
spin_lock(&ubi->wl_lock);
1096-
wl_tree_add(e, &ubi->free);
1097-
ubi->free_count++;
1082+
1083+
if (!ubi->fm_anchor && e->pnum < UBI_FM_MAX_START) {
1084+
ubi->fm_anchor = e;
1085+
ubi->fm_do_produce_anchor = 0;
1086+
} else {
1087+
wl_tree_add(e, &ubi->free);
1088+
ubi->free_count++;
1089+
}
1090+
10981091
spin_unlock(&ubi->wl_lock);
10991092

11001093
/*
@@ -1882,6 +1875,9 @@ int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai)
18821875
if (err)
18831876
goto out_free;
18841877

1878+
#ifdef CONFIG_MTD_UBI_FASTMAP
1879+
ubi_ensure_anchor_pebs(ubi);
1880+
#endif
18851881
return 0;
18861882

18871883
out_free:

drivers/mtd/ubi/wl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#ifndef UBI_WL_H
33
#define UBI_WL_H
44
#ifdef CONFIG_MTD_UBI_FASTMAP
5-
static int anchor_pebs_available(struct rb_root *root);
65
static void update_fastmap_work_fn(struct work_struct *wrk);
76
static struct ubi_wl_entry *find_anchor_wl_entry(struct rb_root *root);
87
static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi);

fs/jffs2/nodelist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ static int jffs2_add_frag_to_fragtree(struct jffs2_sb_info *c, struct rb_root *r
226226
lastend = this->ofs + this->size;
227227
} else {
228228
dbg_fragtree2("lookup gave no frag\n");
229-
return -EINVAL;
229+
lastend = 0;
230230
}
231231

232232
/* See if we ran off the end of the fragtree */

fs/ubifs/debug.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2737,18 +2737,6 @@ static ssize_t dfs_file_write(struct file *file, const char __user *u,
27372737
struct dentry *dent = file->f_path.dentry;
27382738
int val;
27392739

2740-
/*
2741-
* TODO: this is racy - the file-system might have already been
2742-
* unmounted and we'd oops in this case. The plan is to fix it with
2743-
* help of 'iterate_supers_type()' which we should have in v3.0: when
2744-
* a debugfs opened, we rember FS's UUID in file->private_data. Then
2745-
* whenever we access the FS via a debugfs file, we iterate all UBIFS
2746-
* superblocks and fine the one with the same UUID, and take the
2747-
* locking right.
2748-
*
2749-
* The other way to go suggested by Al Viro is to create a separate
2750-
* 'ubifs-debug' file-system instead.
2751-
*/
27522740
if (file->f_path.dentry == d->dfs_dump_lprops) {
27532741
ubifs_dump_lprops(c);
27542742
return count;

fs/ubifs/journal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ static void mark_inode_clean(struct ubifs_info *c, struct ubifs_inode *ui)
503503
static void set_dent_cookie(struct ubifs_info *c, struct ubifs_dent_node *dent)
504504
{
505505
if (c->double_hash)
506-
dent->cookie = prandom_u32();
506+
dent->cookie = (__force __le32) prandom_u32();
507507
else
508508
dent->cookie = 0;
509509
}
@@ -899,7 +899,7 @@ int ubifs_jnl_write_inode(struct ubifs_info *c, const struct inode *inode)
899899
fname_name(&nm) = xent->name;
900900
fname_len(&nm) = le16_to_cpu(xent->nlen);
901901

902-
xino = ubifs_iget(c->vfs_sb, xent->inum);
902+
xino = ubifs_iget(c->vfs_sb, le64_to_cpu(xent->inum));
903903
if (IS_ERR(xino)) {
904904
err = PTR_ERR(xino);
905905
ubifs_err(c, "dead directory entry '%s', error %d",

fs/ubifs/orphan.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -631,12 +631,17 @@ static int do_kill_orphans(struct ubifs_info *c, struct ubifs_scan_leb *sleb,
631631
ino_t inum;
632632
int i, n, err, first = 1;
633633

634+
ino = kmalloc(UBIFS_MAX_INO_NODE_SZ, GFP_NOFS);
635+
if (!ino)
636+
return -ENOMEM;
637+
634638
list_for_each_entry(snod, &sleb->nodes, list) {
635639
if (snod->type != UBIFS_ORPH_NODE) {
636640
ubifs_err(c, "invalid node type %d in orphan area at %d:%d",
637641
snod->type, sleb->lnum, snod->offs);
638642
ubifs_dump_node(c, snod->node);
639-
return -EINVAL;
643+
err = -EINVAL;
644+
goto out_free;
640645
}
641646

642647
orph = snod->node;
@@ -663,20 +668,18 @@ static int do_kill_orphans(struct ubifs_info *c, struct ubifs_scan_leb *sleb,
663668
ubifs_err(c, "out of order commit number %llu in orphan node at %d:%d",
664669
cmt_no, sleb->lnum, snod->offs);
665670
ubifs_dump_node(c, snod->node);
666-
return -EINVAL;
671+
err = -EINVAL;
672+
goto out_free;
667673
}
668674
dbg_rcvry("out of date LEB %d", sleb->lnum);
669675
*outofdate = 1;
670-
return 0;
676+
err = 0;
677+
goto out_free;
671678
}
672679

673680
if (first)
674681
first = 0;
675682

676-
ino = kmalloc(UBIFS_MAX_INO_NODE_SZ, GFP_NOFS);
677-
if (!ino)
678-
return -ENOMEM;
679-
680683
n = (le32_to_cpu(orph->ch.len) - UBIFS_ORPH_NODE_SZ) >> 3;
681684
for (i = 0; i < n; i++) {
682685
union ubifs_key key1, key2;

0 commit comments

Comments
 (0)